3v4l.org

run code in 300+ PHP versions simultaneously
<?php //Case Battle Fairness | Round Validation $serverSeed = ''; // Server seed $eosBlockSeed = ''; // EOS Block Seed /* * This is the round number, where 1 round is one case opened. If the battle has 10 cases, * this means there are 10 rounds - 1-10. * IMPORTANT: If it's the tiebreaker round, it will always be totalRounds + 1 * because the tiebreaker is considered as one additional round. If you have 2 cases * which results in 2 rounds, the tiebreaker roundNumber is 3 because it's total (2) + 1. */ $roundNumber = -1; /* * Player position that we want to validate the roll for. * For example, if you want to validate your own roll and you were holding * the 3rd position from left to right, then playerPosition will be 3. */ $playerPosition = -1; // The Player Position (1 to 4) // 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 == '' || $roundNumber < 0 || $playerPosition < 1 || $playerPosition > 4 || $ticketQuantity <= 0) { 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'); 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; } function getProvablyFairResult(string $init, int $qty): array { $preResult = hash(HASH_TYPE, $init); $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); if ($isTiebreaker) { $stringToHash = "$serverSeed-$eosBlockSeed-$roundNumber"; } else { $stringToHash = "$serverSeed-$eosBlockSeed-$roundNumber-$playerPosition"; } $result = getProvablyFairResult($stringToHash, $ticketQuantity); echo "Result: {$result['result']}"; ?>
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.29, 8.4.1 - 8.4.16, 8.5.0 - 8.5.1
Fill in details
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Parse error: syntax error, unexpected ':', expecting '{' in /in/SCdP9 on line 49
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected ':', expecting '{' in /in/SCdP9 on line 49
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting ')' in /in/SCdP9 on line 49
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_STRING, expecting ')' in /in/SCdP9 on line 49
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/SCdP9 on line 49
Process exited with code 255.

preferences:
111.05 ms | 412 KiB | 5 Q