The most important thing about a lottery is that it is fair. For this reason this lotto is made provably fair. This means that users will be able to verify the outcome. The server hash is obtained by hashing the server seed, which is a secret used to perform the calculations. The sha256 hash of the server seed is unique and can be used to verify after the drawing the server seed was not changed. As the server seed is revealed after the drawing.

Also used in the calculation is the transaction_id of the last person who bought a ticket. This is a random string which cannot influenced. This prevents calculating in advance which ticket will win and buying the ticket with a separate bot.

To calculate which tickets will win the server hash, transaction id, a colon and a roll number(starting from 0) are string together. This string is hashed with a hmac-sha512() function that gives a 128 character hex string. From this string the first 5 characters are taken and converted to a decimal number. This number will be between 0 and 1048575. If this number corresponds to a ticket number there is a winner, if not the roll number will increase by 1. This process repeats itself until all winners are decided. Each ticket can only win once. Below is a rough outline of the process.

# Based on the amount of tickets in the draw
winning_tickets = []
index = 0

while len(winning_numbers) < number_of_winning_tickets:
hash = server_seed + transaction_id : index,

// Take first 5 characters of the hash and convert to decimal number
roll = int(hash[: 5], 16)
if roll < number_of_winning_tickets and roll not in winning_tickets:
    winning_numbers.append((index, roll))
index += 1