3v4l.org

run code in 500+ PHP versions simultaneously
<?php /* * Fill in all four below and click the blue 'eval();' button. * ------------------ */ $server_seed = ""; $client_seed = ""; $game_id = ""; $mine_count = 3; /* ------------------ */ if ($server_seed == '' || $client_seed === "" || $game_id == '') { echo "Fill in details"; return; } $grid_size = 25; // Same hex-to-decimal-via-bcmath approach as the other games, reused per shuffle step. function hmac_mod($server_seed, $message, $modulus) { $hmac_hash = hash_hmac('sha256', $message, $server_seed); $decimal_value = '0'; $length = strlen($hmac_hash); for ($i = 0; $i < $length; $i++) { $decimal_value = bcmul($decimal_value, '16'); $decimal_value = bcadd($decimal_value, hexdec($hmac_hash[$i])); } return (int) bcmod($decimal_value, (string) $modulus); } // Fisher-Yates shuffle over all 25 tiles — one HMAC draw per swap, identical // to get_mines_positions() server-side. Message per step i is // "{client_seed}-{game_id}-{i}", modulus is i+1. $positions = range(0, $grid_size - 1); for ($i = $grid_size - 1; $i > 0; $i--) { $message = $client_seed . "-" . $game_id . "-" . $i; $r = hmac_mod($server_seed, $message, $i + 1); $tmp = $positions[$i]; $positions[$i] = $positions[$r]; $positions[$r] = $tmp; } $mine_positions = array_slice($positions, 0, $mine_count); sort($mine_positions); echo "Mine positions: " . implode(", ", $mine_positions); ?>
Output for 8.2.31 - 8.2.32, 8.3.0 - 8.3.32, 8.4.1 - 8.4.24, 8.5.0 - 8.5.9
Fill in details

preferences:
46.93 ms | 761 KiB | 4 Q