1--TEST--
2Random: Engine: Xoshiro256StarStar: The seed parameter must work as expected
3--FILE--
4<?php declare(strict_types = 1);
5
6use Random\Engine\Xoshiro256StarStar;
7
8echo "Random integer seed", PHP_EOL;
9$engine = new Xoshiro256StarStar(random_int(PHP_INT_MIN, PHP_INT_MAX));
10echo PHP_EOL, PHP_EOL;
11
12echo "Random string seed", PHP_EOL;
13$engine = new Xoshiro256StarStar(random_bytes(32));
14echo PHP_EOL, PHP_EOL;
15
16echo "Invalid data type", PHP_EOL;
17try {
18    $engine = new Xoshiro256StarStar(1.0);
19} catch (Throwable $e) {
20    echo $e->getMessage(), PHP_EOL;
21}
22echo PHP_EOL, PHP_EOL;
23
24echo "Invalid string seed length", PHP_EOL;
25try {
26    $engine = new Xoshiro256StarStar('foobar');
27} catch (Throwable $e) {
28    echo $e->getMessage(), PHP_EOL;
29}
30echo PHP_EOL, PHP_EOL;
31
32echo "Null seed", PHP_EOL;
33try {
34    $engine = new Xoshiro256StarStar(str_repeat("\x00", 32));
35} catch (Throwable $e) {
36    echo $e->getMessage(), PHP_EOL;
37}
38echo PHP_EOL, PHP_EOL;
39
40echo "Valid string seed", PHP_EOL;
41$engine = new Xoshiro256StarStar(str_repeat("\x01\x02\x03\x04\x05\x06\x07\x08", 4));
42
43var_dump($engine);
44
45for ($i = 0; $i < 1000; $i++) {
46    $engine->generate();
47}
48
49var_dump(bin2hex($engine->generate()));
50
51?>
52--EXPECTF--
53Random integer seed
54
55
56Random string seed
57
58
59Invalid data type
60Random\Engine\Xoshiro256StarStar::__construct(): Argument #1 ($seed) must be of type string|int|null, float given
61
62
63Invalid string seed length
64Random\Engine\Xoshiro256StarStar::__construct(): Argument #1 ($seed) must be a 32 byte (256 bit) string
65
66
67Null seed
68Random\Engine\Xoshiro256StarStar::__construct(): Argument #1 ($seed) must not consist entirely of NUL bytes
69
70
71Valid string seed
72object(Random\Engine\Xoshiro256StarStar)#%d (%d) {
73  ["__states"]=>
74  array(4) {
75    [0]=>
76    string(16) "0102030405060708"
77    [1]=>
78    string(16) "0102030405060708"
79    [2]=>
80    string(16) "0102030405060708"
81    [3]=>
82    string(16) "0102030405060708"
83  }
84}
85string(16) "90a025df9300cfd1"
86