1--TEST--
2Random: Randomizer: getInt(): Basic functionality
3--FILE--
4<?php
5
6use Random\Engine;
7use Random\Engine\Mt19937;
8use Random\Engine\PcgOneseq128XslRr64;
9use Random\Engine\Secure;
10use Random\Engine\Test\TestShaEngine;
11use Random\Engine\Xoshiro256StarStar;
12use Random\Randomizer;
13
14require __DIR__ . "/../../engines.inc";
15
16$engines = [];
17$engines[] = new Mt19937(null, MT_RAND_MT19937);
18$engines[] = new Mt19937(null, MT_RAND_PHP);
19$engines[] = new PcgOneseq128XslRr64();
20$engines[] = new Xoshiro256StarStar();
21$engines[] = new Secure();
22$engines[] = new TestShaEngine();
23$iterations = getenv("SKIP_SLOW_TESTS") ? 3_000 : 10_000;
24
25foreach ($engines as $engine) {
26    echo $engine::class, PHP_EOL;
27
28    $randomizer = new Randomizer($engine);
29
30    // Basic range test.
31    for ($i = 0; $i < $iterations; $i++) {
32        $result = $randomizer->getInt(-$i, $i);
33
34        if ($result > $i || $result < -$i) {
35            die("failure: out of range at {$i}");
36        }
37    }
38
39    // Test that extreme ranges do not throw.
40    for ($i = 0; $i < $iterations; $i++) {
41        $randomizer->getInt(PHP_INT_MIN, PHP_INT_MAX);
42    }
43}
44
45die('success');
46
47?>
48--EXPECTF--
49Deprecated: Constant MT_RAND_PHP is deprecated in %s on line %d
50
51Deprecated: The MT_RAND_PHP variant of Mt19937 is deprecated in %s on line %d
52Random\Engine\Mt19937
53Random\Engine\Mt19937
54Random\Engine\PcgOneseq128XslRr64
55Random\Engine\Xoshiro256StarStar
56Random\Engine\Secure
57Random\Engine\Test\TestShaEngine
58success
59