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 (!is_int($res) || $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.5,
28			 10.5e3,
29			 0x10,
30			 0400);
31
32$max = array(100,
33			 1000,
34			 19.5,
35			 10.5e5,
36			 0x10000,
37			 0700);
38
39for ($x = 0; $x < count($min); $x++) {
40	for ($i = 0; $i < 100; $i++) {
41		$res = rand($min[$x], $max[$x]);
42
43		if (!is_int($res) || $res < intval($min[$x]) || $res > intval($max[$x])) {
44			echo "FAILED: res = ",  $res, " min = ", intval($min[$x]), " max = ", intval($max[$x]), "\n";
45			break;
46		}
47	}
48
49	if ($i == 100) {
50		echo "PASSED: range min = ", intval($min[$x]), " max = ", intval($max[$x]), "\n";
51	}
52}
53
54echo "\nNon-numeric cases\n";
55$min = array(true,
56			 false,
57			 null,
58			 "10",
59			 "0x10",
60			 "10.5");
61
62// Eexepcted numerical equivalent of above non-numerics
63$minval = array(1,
64				0,
65				0,
66				10,
67				0,
68				10);
69for ($x = 0; $x < count($min); $x++) {
70	for ($i = 0; $i < 100; $i++) {
71		$res = rand($min[$x], 100);
72
73		if (!is_int($res) || $res < intval($minval[$x]) || $res > 100) {
74			echo "FAILED: res = ",  $res, " min = ", intval($min[$x]), " max = ", intval($max[$x]), "\n";
75			break;
76		}
77	}
78
79	if ($i == 100) {
80		echo "PASSED range min = ", intval($min[$x]), " max = 100\n";
81	}
82}
83?>
84--EXPECTF--
85
86rand() tests with default min and max value (i.e 0 thru %i)
87PASSED: range min = 0 max = %i
88
89rand() tests with defined min and max value
90PASSED: range min = 10 max = 100
91PASSED: range min = 100 max = 1000
92PASSED: range min = 10 max = 19
93PASSED: range min = 10500 max = 1050000
94PASSED: range min = 16 max = 65536
95PASSED: range min = 256 max = 448
96
97Non-numeric cases
98PASSED range min = 1 max = 100
99PASSED range min = 0 max = 100
100PASSED range min = 0 max = 100
101PASSED range min = 10 max = 100
102PASSED range min = 0 max = 100
103PASSED range min = 10 max = 100
104