gmp_random_bits.phpt 946 B

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