1--TEST--
2Test mt_rand() - basic function test mt_rand()
3--FILE--
4<?php
5$default_max = mt_getrandmax();
6
7echo "\nmt_rand() tests with default min and max value (i.e 0 thru ", $default_max, ")\n";
8for ($i = 0; $i < 100; $i++) {
9    $res = mt_rand();
10
11// By default RAND_MAX is 32768 although no constant is defined for it for user space apps
12    if ($res < 0 || $res > $default_max) {
13        break;
14    }
15}
16
17if ($i != 100) {
18    echo "FAILED: res = ",  $res, " min = 0 max = ", $default_max, "\n";
19} else {
20    echo "PASSED: range min = 0  max = ", $default_max, "\n";
21}
22
23echo "\nmt_rand() tests with defined min and max value\n";
24
25$min = array(10,
26             100,
27             10.5e3,
28             0x10,
29             0400);
30
31$max = array(100,
32             1000,
33             10.5e5,
34             0x10000,
35             0700);
36
37for ($x = 0; $x < count($min); $x++) {
38    for ($i = 0; $i < 100; $i++) {
39        $res = mt_rand($min[$x], $max[$x]);
40
41        if (!is_int($res) || $res < intval($min[$x]) || $res > intval($max[$x])) {
42            echo "FAILED: res = ",  $res, " min = ", intval($min[$x]), " max = ", intval($max[$x]), "\n";
43            break;
44        }
45    }
46
47    if ($i == 100) {
48        echo "PASSED: range min = ", intval($min[$x]), " max = ", intval($max[$x]), "\n";
49    }
50}
51
52?>
53--EXPECT--
54mt_rand() tests with default min and max value (i.e 0 thru 2147483647)
55PASSED: range min = 0  max = 2147483647
56
57mt_rand() tests with defined min and max value
58PASSED: range min = 10 max = 100
59PASSED: range min = 100 max = 1000
60PASSED: range min = 10500 max = 1050000
61PASSED: range min = 16 max = 65536
62PASSED: range min = 256 max = 448
63
64