xref: /PHP-5.6/ext/gmp/tests/gmp_random_bits.phpt (revision 25e45a93)
1--TEST--
2gmp_random_bits() basic tests
3--SKIPIF--
4<?php if (!extension_loaded("gmp")) print "skip"; ?>
5--FILE--
6<?php
7
8var_dump(gmp_random_bits());
9var_dump(gmp_random_bits(0));
10var_dump(gmp_random_bits(-1));
11
12// If these error the test fails.
13gmp_random_bits(1);
14gmp_random_bits(1024);
15
16// 0.5 seconds to make sure the numbers stay in range
17$start = microtime(true);
18$limit = (2 ** 30) - 1;
19while (1) {
20	for ($i = 0; $i < 5000; $i++) {
21		$result = gmp_random_bits(30);
22		if ($result < 0 || $result > $limit) {
23			print "RANGE VIOLATION\n";
24			var_dump($result);
25			break 2;
26		}
27	}
28
29	if (microtime(true) - $start > 0.5) {
30		break;
31	}
32}
33
34echo "Done\n";
35?>
36--EXPECTF--
37Warning: gmp_random_bits() expects exactly 1 parameter, 0 given in %s on line %d
38NULL
39
40Warning: gmp_random_bits(): The number of bits must be positive in %s on line %d
41bool(false)
42
43Warning: gmp_random_bits(): The number of bits must be positive in %s on line %d
44bool(false)
45Done
46