3v4l.org

run code in 300+ PHP versions simultaneously
} <?php //Case Battle Fairness | Round Validation $serverSeed = 'cef7544d66f612a41121f506a2903135'; // Server seed $eosBlockSeed = '1a869e974688d612eae6886a5813c2d67da069f3be2b3bf23d381cf2705c9dab'; // EOS Block Seed // Update this to true if you are validating a tiebreaker result. $isTiebreaker = false; /* * Case Ticket's Quantity, by default it's 100,000 * We only change this if there's a case that has different ticket distribution. * Right now, all cases use 100,000 by default. * IMPORTANT: If it's the tiebreaker round, this will be number of players participating on the tiebreaker. * For example, if two players are participating on a tiebreaker the ticketQuantity is 2. */ $ticketQuantity = 100000; /* ------------------ */ if ($serverSeed == '' || $eosBlockSeed == '') { echo "Fill in details"; return; } define('MAX_HEX_SEGMENTS', 6); define('HEX_SEGMENT_SIZE', 2); define('BASE_FOR_HEX_CONVERSION', 256); define('HASH_TYPE', 'sha256'); if (!function_exists('calculateDecimalValue')) { function calculateDecimalValue(string $preResult): float { $decimalValue = 0; for ($i = 0; $i < MAX_HEX_SEGMENTS; $i++) { $hexValue = substr($preResult, HEX_SEGMENT_SIZE * $i, HEX_SEGMENT_SIZE); $decimalValue += hexdec($hexValue) / pow(BASE_FOR_HEX_CONVERSION, $i + 1); } return $decimalValue; } } if (!function_exists('getProvablyFairResult')) { function getProvablyFairResult(string $init, string $serverSeed, int $qty): array { $preResult = hash_hmac(HASH_TYPE, $init, $serverSeed); $decimalValue = calculateDecimalValue($preResult); $result = (int) ($decimalValue * $qty) + 1; return [ 'preResult' => $preResult, 'result' => $result, ]; } } $serverSeed = preg_replace("/\r|\n/", "", $serverSeed); $eosBlockSeed = preg_replace("/\r|\n/", "", $eosBlockSeed); // Print header echo "Case Battle Fairness Validation Results\n"; echo "=====================================\n"; echo "Server Seed: " . substr($serverSeed, 0, 16) . "...\n"; echo "EOS Block Seed: " . substr($eosBlockSeed, 0, 32) . "...\n"; echo "Ticket Quantity: " . number_format($ticketQuantity) . "\n\n"; // Create table header echo str_pad("Round", 7) . " | "; for ($player = 1; $player <= 4; $player++) { echo str_pad("Player $player", 12) . " | "; } echo "\n"; echo str_repeat("-", 7) . " | " . str_repeat(str_repeat("-", 12) . " | ", 4) . "\n"; // Calculate and display results for all rounds and players for ($roundNumber = 1; $roundNumber <= 50; $roundNumber++) { echo str_pad($roundNumber, 7, " ", STR_PAD_LEFT) . " | "; for ($playerPosition = 1; $playerPosition <= 4; $playerPosition++) { if ($isTiebreaker) { $stringToHash = "$eosBlockSeed-$roundNumber"; } else { $stringToHash = "$eosBlockSeed-$roundNumber-$playerPosition"; } $result = getProvablyFairResult($stringToHash, $serverSeed, $ticketQuantity); echo str_pad(number_format($result['result']), 12, " ", STR_PAD_LEFT) . " | "; } echo "\n"; // Add a separator line every 10 rounds for better readability if ($roundNumber % 10 == 0 && $roundNumber < 50) { echo str_repeat("-", 7) . " | " . str_repeat(str_repeat("-", 12) . " | ", 4) . "\n"; } } echo "\n\nNote: Each result represents the ticket number (1 to " . number_format($ticketQuantity) . ") that won for that player in that round.\n"; // Optional: Show example of hash calculation for verification echo "\n\nExample Verification (Round 1, Player 1):\n"; echo "==========================================\n"; $exampleString = "$eosBlockSeed-1-1"; $exampleResult = getProvablyFairResult($exampleString, $serverSeed, $ticketQuantity); echo "Input String: " . substr($exampleString, 0, 50) . "...\n"; echo "HMAC-SHA256 Hash: " . $exampleResult['preResult'] . "\n"; echo "Result: " . number_format($exampleResult['result']) . "\n"; ?>

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.4.120.0040.00524.04
8.4.110.0040.00718.95
8.4.100.0130.01118.79
8.4.90.0210.00920.74
8.4.80.0150.00717.94
8.4.70.0270.00317.66
8.4.60.0170.00918.17
8.4.50.0170.00617.57
8.4.40.0210.00317.80
8.4.30.0200.00517.88
8.4.20.0200.00517.67
8.4.10.0190.00517.77
8.3.250.0070.00417.44
8.3.240.0120.01017.29
8.3.230.0180.00416.89
8.3.220.0170.00517.06
8.3.210.0170.00516.80
8.3.200.0140.00717.18
8.3.190.0200.00716.79
8.3.180.0440.00616.72
8.3.170.0400.01016.76
8.3.160.0370.00516.92
8.3.150.0210.00416.93
8.3.140.0180.00516.97
8.3.130.0180.00316.99
8.3.120.0220.00816.98
8.3.110.0340.01116.64
8.3.100.0290.00717.01
8.3.90.0450.01016.66
8.3.80.0260.00617.00
8.3.70.0360.00616.85
8.3.60.0240.00316.47
8.3.50.0350.00917.00
8.3.40.0350.01018.10
8.3.30.0280.01017.87
8.3.20.0320.00817.70
8.3.10.0310.00617.75
8.3.00.0230.00617.67
8.2.290.0260.01216.89
8.2.280.0320.00817.02
8.2.270.0350.00916.84
8.2.260.0270.00316.58
8.2.250.0180.00416.79
8.2.240.0180.00616.52
8.2.230.0190.00316.54
8.2.220.0350.01116.73
8.2.210.0310.01216.30
8.2.200.0370.01116.76
8.2.190.0400.00616.51
8.2.180.0340.00916.86
8.2.170.0290.00917.98
8.2.160.0330.01018.07
8.2.150.0260.00617.84
8.2.140.0390.00917.87
8.2.130.0280.00617.85
8.2.120.0330.01217.91
8.2.110.0140.00718.05
8.2.100.0300.01117.74
8.2.90.0360.00517.79
8.2.80.0150.00617.68
8.2.70.0260.00817.75
8.2.60.0340.01217.94
8.2.50.0380.00617.75
8.2.40.0350.01017.71
8.2.30.0280.01017.53
8.2.20.0130.00617.64
8.2.10.0130.00817.66
8.2.00.0170.00317.73

preferences:
28.82 ms | 403 KiB | 5 Q