1--TEST--
2Random: Randomizer: Serialization of the Randomizer must preserve the sequence
3--FILE--
4<?php
5
6use Random\Engine;
7use Random\Engine\Mt19937;
8use Random\Engine\PcgOneseq128XslRr64;
9use Random\Engine\Test\TestShaEngine;
10use Random\Engine\Xoshiro256StarStar;
11use Random\Randomizer;
12
13require __DIR__ . "/../engines.inc";
14
15$engines = [];
16$engines[] = new Mt19937(1234, MT_RAND_MT19937);
17$engines[] = new Mt19937(1234, MT_RAND_PHP);
18$engines[] = new PcgOneseq128XslRr64(1234);
19$engines[] = new Xoshiro256StarStar(1234);
20$engines[] = new TestShaEngine("1234");
21$iterations = getenv("SKIP_SLOW_TESTS") ? 3_000 : 10_000;
22
23foreach ($engines as $engine) {
24    echo $engine::class, PHP_EOL;
25
26    $randomizer = new Randomizer($engine);
27
28    for ($i = 0; $i < 10_000; $i++) {
29        $randomizer->getInt(0, $i);
30    }
31
32    $randomizer2 = unserialize(serialize($randomizer));
33
34    for ($i = 0; $i < $iterations; $i++) {
35        if ($randomizer->getInt(0, $i) !== $randomizer2->getInt(0, $i)) {
36            $className = $engine::class;
37
38            die("failure: state differs at {$i}");
39        }
40    }
41}
42
43die('success');
44?>
45--EXPECTF--
46Deprecated: Constant MT_RAND_PHP is deprecated in %s on line %d
47
48Deprecated: The MT_RAND_PHP variant of Mt19937 is deprecated in %s on line %d
49Random\Engine\Mt19937
50Random\Engine\Mt19937
51Random\Engine\PcgOneseq128XslRr64
52Random\Engine\Xoshiro256StarStar
53Random\Engine\Test\TestShaEngine
54success
55