3v4l.org

run code in 300+ PHP versions simultaneously
<?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.2.29 - 7.2.33, 7.3.16 - 7.3.33, 7.4.3 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught Error: Call to undefined function openssl_random_pseudo_bytes() in /in/6kiie:11 Stack trace: #0 /in/6kiie(16): generateRandomNumber() #1 {main} thrown in /in/6kiie on line 11
Process exited with code 255.
Output for 7.2.0
-8391276657161234432
Output for 7.1.7
-5750479181002315776
Output for 7.1.6
-896674385891481600
Output for 7.1.5
-1671379867586349056
Output for 7.1.0
-1961909164112439296
Output for 7.0.20
4946983792325200826
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 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.3.29, 5.4.0 - 5.4.14, 5.4.25 - 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.4.24
-8532105209084313600
Output for 5.4.23
-5825928252289337344
Output for 5.4.22
-8860479975107657728
Output for 5.4.21
2409573310706044819
Output for 5.4.20
3147938098791102265
Output for 5.4.19
7101165933959020886
Output for 5.4.18
-1369125358301444096
Output for 5.4.17
4434372820001380282
Output for 5.4.16
-7574676050814425088
Output for 5.4.15
-4258533112120092672
Output for 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 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.3.11, 4.4.0 - 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.

preferences:
211.24 ms | 401 KiB | 309 Q