3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function generateRandomNumber($min = 0, $max = PHP_INT_MAX) { $range = max($max, $min) - min($max, $min); if (0 == $range) { throw new \Exception('Cannot create a random number with range = 0 ($min and $max are the same).'); } $byteLength = (int) (log($range, 2) / 8) + 1; $random = hexdec(bin2hex(openssl_random_pseudo_bytes($byteLength))) % $range; return $min + $random; } echo generateRandomNumber();
Output for 7.1.0
-1961909164112439296
Output for 7.0.14
3640496875041482644
Output for 7.0.6
7619099664526354953
Output for 7.0.5
8229552158721575266
Output for 7.0.4
1510656953538524208
Output for 7.0.3
1700387956912558614
Output for 7.0.2
4802520305041067043
Output for 7.0.1
1433434085744316209
Output for 7.0.0
-2877966676870825984
Output for hhvm-3.12.0
-4148439075202666496
Output for hhvm-3.10.0

Process exited with code 153.
Output for 5.6.28
3571423836561779003
Output for 5.6.21
6914290925845484147
Output for 5.6.20
226579882892789319
Output for 5.6.19
-4533369337346983936
Output for 5.6.18
-1939207265558368256
Output for 5.6.17
2232142305002700910
Output for 5.6.16
-967903569193091072
Output for 5.6.15
-2636623543678824448
Output for 5.6.14
-8543962015788867584
Output for 5.6.13
-3539987937816176640
Output for 5.6.12
-1871097245668517888
Output for 5.6.11
-7933402277244506112
Output for 5.6.10
-3923921054324652032
Output for 5.6.9
7118097343364704833
Output for 5.6.8
2317814003394247024
Output for 5.5.35
3728492165203508582
Output for 5.5.34
1485096006380760924
Output for 5.5.33
-1253034851830304768
Output for 5.5.32
6257191414034097890
Output for 5.5.31
417248691412739384
Output for 5.5.30
-3659221375837911040
Output for 5.5.29
-5244852476761862144
Output for 5.5.28
-243771157514358784
Output for 5.5.27
-2115276014288023552
Output for 5.5.26
-2004417226580584448
Output for 5.5.25
-4284570583697754112
Output for 5.5.24
-1817695942508107776
Output for 5.4.45
7675419130738473032
Output for 5.4.44
2648614013984255313
Output for 5.4.43
4597817149036236011
Output for 5.4.42
3322760005777208729
Output for 5.4.41
2740021756132339550
Output for 5.4.40
4434734114398180536
Output for 5.4.39
8390903387787674334
Output for 5.4.38
-3637981950304802816
Output for 5.4.37
-46606369906493440
Output for 5.4.36
-5217746784335321088
Output for 5.3.0 - 5.4.35
Fatal error: Call to undefined function openssl_random_pseudo_bytes() in /in/6kiie on line 11
Process exited with code 255.
Output for 5.0.5 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/6kiie on line 7 Fatal error: Call to undefined function openssl_random_pseudo_bytes() in /in/6kiie on line 11
Process exited with code 255.
Output for 5.0.3 - 5.0.4
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/6kiie on line 7 Notice: Use of undefined constant PHP_INT_MAX - assumed 'PHP_INT_MAX' in /in/6kiie on line 2 Fatal error: Uncaught exception 'Exception' with message 'Cannot create a random number with range = 0 ($min and $max are the same).' in /in/6kiie:7 Stack trace: #0 /in/6kiie(7): generateRandomNumber() #1 /in/6kiie(16): generateRandomNumber() #2 {main} thrown in /in/6kiie on line 7
Process exited with code 255.
Output for 5.0.0 - 5.0.2
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/6kiie on line 7 Notice: Use of undefined constant PHP_INT_MAX - assumed 'PHP_INT_MAX' in /in/6kiie on line 2 Fatal error: Uncaught exception 'Exception' with message 'Cannot create a random number with range = 0 ($min and $max are the same).' in /in/6kiie:7 Stack trace: #0 /in/6kiie(16): generateRandomNumber() #1 {main} thrown in /in/6kiie on line 7
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_NEW in /in/6kiie on line 7
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_NEW in /in/6kiie on line 7
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/6kiie on line 7
Process exited with code 255.