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"; ?>
Output for git.master, git.master_jit
Fill in details

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
44.83 ms | 762 KiB | 4 Q