3v4l.org

run code in 300+ PHP versions simultaneously
<?php class PseudoRandomSequence { const STATE_HASH = "sha512"; // 1/2 STATE_HASH block size, const STATE_SIZE = 32; private $state; public function __construct($state) { $this->state = $state; $this->mixState(); } public function int($min = 0, $max = PHP_INT_MAX) { $range = $max - $min; if ($range <= 0 || is_float($range)) { throw new Exception("Invalid min/max provided"); } $bits = 0; $tmp = $range; while ($tmp >>= 1) { $bits++; } $bytes = (int) max(ceil($bits / 8), 1); $mask = pow(2, $bits) - 1; do { $rand = $this->bytes($bytes); $result = hexdec(bin2hex($rand)) & $mask; } while ($result > $range); return $result + $min; } public function bytes($n) { $ret = ''; do { $ret .= $this->mixState(); } while (strlen($ret) < $n); return substr($ret, 0, $n); } private function mixState() { $hash = hash(self::STATE_HASH, $this->state, true); $this->state = $hash; return substr($hash, self::STATE_SIZE); } } $prng = new PseudoRandomSequence("blah"); for ($i = 0; $i < 100; $i++) { var_dump($prng->int()); }

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.60.0160.00316.73
8.3.50.0120.00418.15
8.3.40.0100.01019.07
8.3.30.0170.00319.04
8.3.20.0040.01120.45
8.3.10.0000.00822.08
8.3.00.0120.00819.38
8.2.180.0100.01318.66
8.2.170.0120.00622.96
8.2.160.0160.00622.34
8.2.150.0030.00624.18
8.2.140.0130.00724.66
8.2.130.0080.00526.16
8.2.120.0030.00619.89
8.2.110.0080.00319.50
8.2.100.0060.00618.28
8.2.90.0060.00317.75
8.2.80.0060.00318.99
8.2.70.0040.00417.75
8.2.60.0030.00617.88
8.2.50.0030.00517.75
8.2.40.0030.00617.75
8.2.30.0050.00317.76
8.2.20.0080.00017.77
8.2.10.0080.00018.18
8.2.00.0000.00817.88
8.1.280.0130.00625.92
8.1.270.0000.01120.90
8.1.260.0060.00326.35
8.1.250.0110.00428.09
8.1.240.0060.00323.96
8.1.230.0120.00019.25
8.1.220.0000.00917.91
8.1.210.0000.00818.77
8.1.200.0030.00617.48
8.1.190.0000.00917.47
8.1.180.0040.00418.10
8.1.170.0000.00817.62
8.1.160.0030.00619.01
8.1.150.0000.00819.02
8.1.140.0030.00517.58
8.1.130.0020.00517.97
8.1.120.0000.00817.48
8.1.110.0000.00817.62
8.1.100.0000.00817.59
8.1.90.0040.00417.61
8.1.80.0030.00517.60
8.1.70.0000.00717.59
8.1.60.0050.00517.77
8.1.50.0030.00617.63
8.1.40.0090.00017.66
8.1.30.0000.00817.80
8.1.20.0000.01017.77
8.1.10.0030.00517.70
8.1.00.0080.00017.51
8.0.300.0070.00318.77
8.0.290.0080.00016.75
8.0.280.0000.00718.23
8.0.270.0040.00418.09
8.0.260.0070.00417.30
8.0.250.0020.00516.98
8.0.240.0080.00017.07
8.0.230.0060.00317.04
8.0.220.0040.00416.98
8.0.210.0020.00517.07
8.0.200.0070.00317.00
8.0.190.0030.00617.15
8.0.180.0080.00017.09
8.0.170.0040.00417.07
8.0.160.0080.00017.08
8.0.150.0000.00716.86
8.0.140.0000.00816.89
8.0.130.0050.00213.41
8.0.120.0040.00416.88
8.0.110.0000.00816.90
8.0.100.0000.00817.04
8.0.90.0040.00416.91
8.0.80.0120.01216.98
8.0.70.0050.00316.94
8.0.60.0030.00517.13
8.0.50.0040.00416.97
8.0.30.0130.01017.22
8.0.20.0170.00617.49
8.0.10.0050.00217.18
8.0.00.0080.01116.87
7.4.330.0060.00015.18
7.4.320.0000.00816.63
7.4.300.0040.00416.71
7.4.290.0080.00016.68
7.4.280.0000.00816.68
7.4.270.0030.00316.65
7.4.260.0000.00716.74
7.4.250.0000.00816.75
7.4.240.0010.00716.66
7.4.230.0040.00416.82
7.4.220.0180.00416.56
7.4.210.0130.00316.79
7.4.200.0040.00416.55
7.4.160.0120.00616.75
7.4.150.0130.00717.40
7.4.140.0110.00917.86
7.4.130.0110.01016.86
7.4.120.0050.01416.75
7.4.110.0130.01316.64
7.4.100.0090.00916.69
7.4.90.0080.01216.56
7.4.80.0130.01419.39
7.4.70.0090.00916.61
7.4.60.0090.00916.66
7.4.50.0000.00816.75
7.4.40.0120.00616.56
7.4.30.0130.01316.46
7.4.00.0070.00715.05
7.3.330.0040.00213.37
7.3.320.0150.00213.53
7.3.310.0040.00416.54
7.3.300.0040.00416.48
7.3.290.0060.00916.50
7.3.280.0060.01016.48
7.3.270.0060.01417.40
7.3.260.0120.00716.45
7.3.250.0160.00416.67
7.3.240.0100.01016.56
7.3.230.0110.01416.69
7.3.210.0120.00616.77
7.3.200.0100.01419.39
7.3.190.0040.01216.61
7.3.180.0060.01016.53
7.3.170.0130.01016.61
7.3.160.0110.00716.52
7.2.330.0120.00916.66
7.2.320.0060.01316.91
7.2.310.0060.01316.87
7.2.300.0110.00616.68
7.2.290.0100.01016.84
7.2.60.0110.01116.46
7.2.00.0030.01019.56
7.1.200.0100.00315.95
7.1.100.0030.01318.35
7.1.70.0060.00917.38
7.1.60.0110.00717.31
7.1.50.0060.01616.92
7.1.00.0070.07022.66
7.0.200.0000.01716.53
7.0.140.0100.06722.20
7.0.60.0100.06020.04
7.0.50.0030.08318.08
7.0.40.0030.04320.11
7.0.30.0330.07320.29
7.0.20.0300.07720.12
7.0.10.0270.08020.16
7.0.00.0170.05320.25
5.6.280.0030.10021.20
5.6.210.0130.07720.81
5.6.200.0000.04318.28
5.6.190.0070.09020.66
5.6.180.0270.07320.49
5.6.170.0400.07320.84
5.6.160.0030.04720.66
5.6.150.0070.03718.30
5.6.140.0030.08318.23
5.6.130.0070.08318.41
5.6.120.0070.04021.18
5.6.110.0070.06021.16
5.6.100.0070.08321.21
5.6.90.0070.09021.07
5.6.80.0070.08020.56
5.6.70.0230.07720.55
5.5.350.0170.07720.54
5.5.340.0000.04318.12
5.5.330.0100.08320.31
5.5.320.0170.03320.40
5.5.310.0300.07720.63
5.5.300.0130.07318.11
5.5.290.0030.07718.02
5.5.280.0130.06021.13
5.5.270.0070.06320.88
5.5.260.0130.07721.05
5.5.250.0070.09320.95
5.5.240.0030.05020.30
5.4.450.0830.06319.32
5.4.440.0530.07319.16
5.4.430.0130.05719.16
5.4.420.0870.05019.45
5.4.410.0200.07019.16
5.4.400.0230.07018.77
5.4.390.0270.06318.77
5.4.380.0330.05718.60
5.4.370.0400.05718.74
5.4.360.0530.07018.79
5.4.350.0500.06318.47
5.4.340.0230.06018.54
5.4.320.0400.07718.73
5.4.310.0400.07318.78
5.4.300.0330.05018.51
5.4.290.0330.06018.73
5.4.280.0370.05718.78
5.4.270.0330.05718.79
5.4.260.0230.06318.61
5.4.250.0370.05318.51
5.4.240.0230.06718.83
5.4.230.0270.06018.61
5.4.220.0270.06018.75
5.4.210.0270.05718.52
5.4.200.0330.04716.53
5.4.190.0330.05318.50
5.4.180.0500.06318.76
5.4.170.0430.06718.45
5.4.160.0270.06718.55
5.4.150.0330.08318.50
5.4.140.0400.07716.28
5.4.130.0470.06716.29
5.4.120.0400.07316.29
5.4.110.0370.07716.28
5.4.100.0400.07016.20
5.4.90.0570.07716.27
5.4.80.0530.06316.29
5.4.70.0530.06316.21
5.4.60.0430.07016.28
5.4.50.0370.05016.11
5.4.40.0300.05716.39
5.4.30.0370.07716.23
5.4.20.0370.05316.15
5.4.10.0400.07716.26
5.4.00.0430.06715.78
5.3.290.0330.06714.66
5.3.280.0270.06714.64
5.3.270.0530.06314.61
5.3.260.0470.07014.66
5.3.250.0500.07014.64
5.3.240.0500.06714.75
5.3.230.0230.06314.71
5.3.220.0400.06014.80
5.3.210.0470.08014.63
5.3.200.0500.07714.75
5.3.190.0530.06314.64
5.3.180.0470.07014.71
5.3.170.0530.06714.68
5.3.160.0530.06014.63
5.3.150.0330.05314.56
5.3.140.0300.05314.62
5.3.130.0300.06014.69
5.3.120.0330.05314.66
5.3.110.0470.04714.74
5.3.100.0300.05714.03
5.3.90.0400.04314.09
5.3.80.0400.04314.07
5.3.70.0330.05014.13
5.3.60.0270.05714.09
5.3.50.0330.05014.09
5.3.40.0330.05314.00
5.3.30.0530.06014.13
5.3.20.0600.05713.75
5.3.10.0570.05713.77
5.3.00.0530.07713.69
5.2.170.0300.06311.29
5.2.160.0400.05311.19
5.2.150.0370.05711.23
5.2.140.0470.05011.29
5.2.130.0370.05711.17
5.2.120.0370.05711.22
5.2.110.0230.04711.16
5.2.100.0230.04711.22
5.2.90.0300.04711.12
5.2.80.0270.04711.15
5.2.70.0430.05011.21
5.2.60.0430.05011.11
5.2.50.0230.07011.07
5.2.40.0230.06011.07
5.2.30.0200.06711.02
5.2.20.0230.06011.09
5.2.10.0330.05010.95
5.2.00.0200.06310.75
5.1.60.0270.04710.00
5.1.50.0400.05010.00
5.1.40.0400.04010.19
5.1.30.0300.05010.37
5.1.20.0300.04710.47
5.1.10.0200.03310.12
5.1.00.0170.04010.28
5.0.50.0070.0338.77
5.0.40.0070.0378.46
5.0.30.0130.0438.32
5.0.20.0100.0308.41
5.0.10.0130.0278.23
5.0.00.0070.0478.21
4.4.90.0130.0306.00
4.4.80.0130.0306.00
4.4.70.0200.0235.90
4.4.60.0130.0305.86
4.4.50.0170.0275.91
4.4.40.0100.0475.93
4.4.30.0200.0235.96
4.4.20.0070.0236.07
4.4.10.0030.0275.92
4.4.00.0030.0405.91
4.3.110.0100.0235.82
4.3.100.0130.0175.93
4.3.90.0100.0205.88
4.3.80.0070.0375.88
4.3.70.0100.0305.91
4.3.60.0070.0335.89
4.3.50.0130.0305.77
4.3.40.0200.0375.76
4.3.30.0000.0275.14
4.3.20.0070.0205.14
4.3.10.0070.0205.14
4.3.00.0130.0277.30

preferences:
45.66 ms | 400 KiB | 5 Q