Provably Fair Gaming
Crash
In Crash, provably fair algorithms ensure fair and verifiable outcomes. The crash point is generated using server seed, public seed, and round number. These values are combined and hashed with the SHA-256 algorithm. The first 13 characters of the hash are converted to an integer. To calculate the crash point, 2^52 is divided by the sum of the integer and 1, multiplied by (1 - 0.04) for the house edge, and rounded to two decimal places. Players can independently verify the crash point using the public seed and round number to confirm the game's fairness.
const hashString = string => crypto.createHash('sha256').update(string).digest('hex'); const generateCrashTicket = (serverSeed, publicSeed, round) => { let combined = `${serverSeed}:${publicSeed}:${round}`; const hash = hashString(combined); return parseInt(hash.substring(0, 13), 16); } let intValue = generateCrashTicket(seed.server_seed, seed.public_seed, seed.round_number); let crashpoint = Math.max(1, (2 ** 52 / (intValue + 1)) * (1 - 0.04)).toFixed(2); if(crashpoint > 20000) { crashpoint = 20000.01; }
Roulette
In Roulette, provably fair algorithms ensure fair and verifiable outcomes. In this multiplayer lobby, round number and public seed are used, with the server seed and public seed cycling every 50 rounds to maintain fairness.
The game rolls a random number between 0 and 14, determining the color and corresponding prize based on players' bets. The outcomes have a 2x multiplier for red (1-7) and black (8-14), and a 14x multiplier for green (0).
The outcome is generated using server seed, public seed, and round number, which are combined and hashed with the SHA-256 algorithm. The first 13 characters of the hash are converted to an integer, and the remainder of the integer divided by 15 is taken as the ticket number.
Players can independently verify the roulette outcome using the public seed and round number, confirming the game's fairness`}.
const hashString = string => crypto.createHash('sha256').update(string).digest('hex'); const generateRouletteTicket = (serverSeed, publicSeed, round) => { let combined = `${serverSeed}:${publicSeed}:${round}`; const hash = hashString(combined); return parseInt(hash.substring(0, 13), 16) % 15; } let ticketNumber = generateRouletteTicket(seed.server_seed, seed.public_seed, seed.round_number); return ticketNumber;
Case Opening
In the Case Opening game, you open a virtual case to receive an item. Each item has a pre-assigned probability of being won, with the sum of all probabilities being 100%. The game rolls a number between 0 and 99,999, and the range that the rolled number falls into determines the item you receive.
The PHP code ensures fairness by creating a randomized roll result using server and client seeds and a unique identifier. This "combined seed" is processed through the SHA-256 hashing algorithm, and the first 13 characters of the resulting hash are converted into a decimal number. The roll result is obtained by taking this number modulo 100,000.
The roll result is then compared with the range of each item in the case. The item corresponding to the range the roll result falls into is the one you win.`}
$hash_seed = hash('sha256', $server_seed . ':' . $client_seed . ':' . $nonce); $roll_result = hexdec(substr($hash_seed, 0, 13)) % 100000; foreach($item_details as $key => $value) { if($roll_result > $value['range_one'] && $roll_result < $value['range_two']) { $winning_item = $value; } }
Dice
In the Dice game, you choose a number and decide if you'll win when the rolled number is higher or lower than your chosen number. The game rolls a number between 0 - 9,999 and multiplies your chosen number by 100 to account for decimals. The game then compares the multiplied number with the rolled number to determine if you've won.
$hash_seed = hash('sha256', $server_seed . ':' . $client_seed . ':' . $nonce); $roll_result_number = hexdec(substr($hash_seed, 0, 13)) % 10000; $roll_convert = $user_roll * 100; if($user_roll_direction) { if($roll_convert < $roll_result_number) { $roll_result = true; } else { $roll_result = false; } } else { if($roll_convert > $roll_result_number) { $roll_result = true; } else { $roll_result = false; } }
Plinko
In the Plinko game, a ball drops through a field of pegs, moving left or right as it hits each peg. The direction of each move is determined randomly with 0 indicating left and 1 indicating right. The ball's final position (or bucket), determined by the sum of all moves, corresponds to a specific prize or multiplier.
$plinko_index = array(); $combined_seed = hash('sha256', $server_seed_value . ':' . $client_seed_value . ':' . $nonce_value); for ($x=0; $x < 64; $x = $x+4) { array_push($plinko_index, $combined_seed[$x] > '7' ? 1:0); } $plinko_index = array_splice($plinko_index, 0, $row_count); $plinko_map = getPlinkoMap($risk_type, $row_count); $multipliers = $plinko_map['multipliers']; $plinko_ticket = array_sum($plinko_index); $bucket = $multipliers[$plinko_ticket];
This block first generates a combined seed using the server seed, client seed, and nonce. This seed is hashed using the SHA-256 algorithm. Then, for every 4 characters in the hashed seed, the code checks if the character is greater than '7'. If it is, it pushes '1' into the $plinko_index array; otherwise, it pushes '0'. This array, after being spliced to the required row count, represents the path of the ball.
The $plinko_map function retrieves the risk type and row count, and $multipliers holds the multipliers for each bucket. The final bucket is determined by summing up the values in the $plinko_index array (i.e., the path of the ball) and using this sum as an index to select the corresponding multiplier from the $multipliers array.