3v4l.org

run code in 500+ PHP versions simultaneously
<?php /* ------------------ */ $server_seed = ""; $round = ""; $number_of_tickets = 0; /* ------------------ */ if ($server_seed == '' || $round == '' || $number_of_tickets == 0) { echo "Fill in details"; return; } // Create HMAC-SHA256 hash $hash = hash_hmac('sha256', (string)$round, $server_seed); // Convert hex to decimal using bcmath $decimal_hash = '0'; $length = strlen($hash); for ($i = 0; $i < $length; $i++) { $decimal_hash = bcmul($decimal_hash, '16'); $decimal_hash = bcadd($decimal_hash, (string)hexdec($hash[$i])); } // Apply modulo to get the winning position $roll = bcmod($decimal_hash, (string)$number_of_tickets); echo "Winning ticket position: $roll\n"; ?>

preferences:
41.73 ms | 764 KiB | 5 Q