1--TEST--
2Test  rand() - basic function test rand()
3--FILE--
4<?php
5$default_max = getrandmax();
6
7echo "\nrand() tests with default min and max value (i.e 0 thru ", $default_max, ")\n";
8for ($i = 0; $i < 100; $i++) {
9    $res = 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 "\nrand() 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 = 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--EXPECTF--
54rand() tests with default min and max value (i.e 0 thru %i)
55PASSED: range min = 0 max = %i
56
57rand() 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