Thursday, May 18, 2017

Proof of the probability fair in roulette

We determine the outcome of roulette game in a provably fair manner. What this means is that the outcome of the game cannot be changed after the game, and the user can easily verify it.

To select the outcome, we use a server seed (long random string) and client seed (long random string). Before every game, the user can note the hash of the server seed. Then after the game , the server seed is revealed and the user can verify that it is the same by calculating its hash.

Hash function is a cyptographic operation which generates a long string from any input string in such a manner that the input string cannot be obtained from the output string and the output string is always the same for same input string. The output string is called hash of input string.

To calculate the outcome from client seed and server seed, we use a cyptographich function which generates hash from server seed and client seed. We take first 5 characters of the hash and then convert it into a number. If the number is below 1000000 we take that number otherwise we take next 5 characters and convert it into a number, till we get a number below 1000000. We take the last 4 digits of this number and divide by 100 to get a number between 0 and 100. Finally, we use this as a percentage value to calculate the outcome index from list of outcomes.

The actual algorithm:
$hmac=hash_hmac('sha512', $serverseed, $clientseed);
$output_index = floor($roll / 100 * $options_count);
$prize = $options[$output_index] * $bet_amount;

No comments:

Post a Comment