To help ensure the winners of games on BitDraw are chosen randomly, BitDraw uses transparent rules combined with external random data to chose winners. The method is as follows:
- Hashing function
- Whenever a hashing function is mentioned below SHA-512 is used.
For each game, 2 sources of 512 bits of data are collected/generated: Once at the start of the game, and once at the end.
At the start of a game, the 1st lot of 512 bits of data are pulled from random.org.
- This 512 bits of data is included in a game signature, a hash of which is displayed to the player. This game signature hash allows users to confirm that BitDraw does not change this pre-selected random data.
- Note: If random.org happens to be unavailable, Ruby's
Random.rand function is used, and the result hashed to generate 512 bits.
At the end of a game, the 2nd lot 512 bits of random data are generated by grabbing the
id of a tweet on Twitter. The tweet used is the one announcing the finishing of the game in question by @BitDrawLottery.
Note: If Twitter happens to be unavailable or returns an error, Ruby's
Random.rand function is used.
id value or Ruby's
Random.rand value are converted to 512 bits by hashing that value.
Once the game has finished and the 2 lots of 512 bits of data have been collected these are XOR'ed to generate a new 512 bits of data derived from the two 512 bit sources.
This resulting 512 bits is used to determine the winner(s) of the game.
For raffles and lotteries, the mechanics are largely the same. For both types, the 512 bits are used to pick items randomly from the possible choices.
The 512 bits are used as an endless bitstream as follows:
Copy the original 512 bits into a bit array.
If X bits are needed,
and there are X+ bits in the current bit array,
then X bits are removed and used from the front of the current bit array.
If X bits are needed, but there are not enough bits, a new 512 bit array is created by hashing the entire current 512 bit array.
- Go back to b.
- Pick X bits from the endless bitstream, where X is the number of bits needed to pick an item from the possible tickets for a raffle. For example, if there are 2 tickets, 1 bit, if there are 3 or 4 tickets we need 2 bits, etc.
Check if the X bits converted to a decimal value map to a valid raffle ticket number.
- If yes, that is the winning ticket.
- If not, got back to a.
- Pick X bits from the endless bitstream, where X is the number of bits needed to pick an item from the pool of lottery items. For example, if there are 8 items in the pool 3 bits are needed, if there are 9-16 items 4 bits are needed, etc.
Check if the X bits map to a valid item in the lottery pool and check that item has not already been chosen.
- If yes, add that item to the accumulate list of winning lottery items.
- If no, go back to a.
If need pick more items, go back to a.
Once all the winning items for the lottery are chosen:
- The winning tickets are all tickets for that game matching the winning lottery items.
- Split the jackpot evenly between winning tickets.