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
22foreach ($engines as $engine) {
23    echo $engine::class, PHP_EOL;
24
25    $randomizer = new Randomizer($engine);
26
27    for ($i = 0; $i < 10_000; $i++) {
28        $randomizer->getInt(0, $i);
29    }
30
31    $randomizer2 = unserialize(serialize($randomizer));
32
33    for ($i = 0; $i < 10_000; $i++) {
34        if ($randomizer->getInt(0, $i) !== $randomizer2->getInt(0, $i)) {
35            $className = $engine::class;
36
37            die("failure: state differs at {$i}");
38        }
39    }
40}
41
42die('success');
43?>
44--EXPECT--
45Random\Engine\Mt19937
46Random\Engine\Mt19937
47Random\Engine\PcgOneseq128XslRr64
48Random\Engine\Xoshiro256StarStar
49Random\Engine\Test\TestShaEngine
50success
51