3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* * Fill in all four below and click the blue 'eval();' button. * ------------------ */ $server_seed = ""; $public_seed = ""; $round = ""; /* ------------------ */ if ($server_seed == '' || $public_seed === "" || $round == '') { echo "Fill in details"; return; } $hash = hash_hmac('sha256', $public_seed . "-" . $round, $server_seed); $decimal_hash = '0'; $length = strlen($hash); for ($i = 0; $i < $length; $i++) { $decimal_hash = bcmul($decimal_hash, '16'); // Multiply by base 16 $decimal_hash = bcadd($decimal_hash, hexdec($hash[$i])); // Add the current digit } // Apply modulo to get the roll $roll = bcmod($decimal_hash, '15'); // Use modulo 15 to get the roll // Determine roll colour based on new logic if (in_array($roll, [0, 2, 4, 6, 9, 11, 13])) { $roll_colour = 'red'; } elseif (in_array($roll, [1, 3, 5, 8, 10, 12, 14])) { $roll_colour = 'black'; } else { $roll_colour = 'green'; } echo("Roll: $roll\nColour: $roll_colour"); ?>
Output for 8.1.34, 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.17, 8.5.0 - 8.5.2
Fill in details

preferences:
61.05 ms | 406 KiB | 5 Q