we.lovebitco.in

Bitcoin blockchain raffle ticket picker


About

If you are running a raffle, you may need to prove to entrants that your ticket-choosing methodology is fair. This page calculates a winner for you using data from the Bitcoin transaction blockchain.

A lottery organizer shall specify a future Bitcoin block number which will decide the winner, a block which will occur after the raffle entrance is closed and a list of ticket numbers and entrants is published. In this manner, a lottery operator can show he isn't picking the ticket number of a friend or conspirator.

A block's hash can be discovered using functions of your own Bitcoin software, or it can be looked up on several web sites:

http://blockchain.info
http://blockexplorer.com

The calculations on this page are performed with JavaScript in your own web browser, no data is communicated.

Technical Info

The Bitcoin currency packages its transactions into secure data blocks about every 10 minutes. Part of the process of securing these transaction blocks creates random data useful for other purposes.

Each bitcoin block has a SHA256(SHA256()) hash that is the main "block hash", a hash of the contents of the block (technically, the top hash of the Merkle tree of the transactions in the block). Hashing algorithms such as SHA256 create a digital fingerprint of data that cannot be easily falsified. 256-bit hash output is an unpredictable random-looking 64-character hex number (it is unpredictable and irreversible by design). This is the puzzle that Bitcoin mining uses to secure the blockchain - since the output of SHA256 is unpredictable, it is very hard to find a hash that looks like something you specify.

Bitcoin's mining challenge is to find a block hash that starts with many zeros, the more zeros desired at the beginning of a 256-bit hash (and the smaller the value), the more difficult it becomes to find one. Only after discovering a hash of a group of transactions that is smaller than the current difficulty target (a different hash is made by adding some random data, a nonce, to the block contents) can a transaction block be added to the blockchain. This process makes falsifying or altering the Bitcoin blockchain computationally difficult.

This hash of a block is used as a random number picker. Since it is so hard to even find a block hash (it's currently worth 12.5BTC just to find a block hash solution), manipulating the blockchain so a hash of a particular block is a particular number is quite impossible, and it is also impossible to predict what a possible hash value might be. Since the blockchain is published peer-to-peer in a secured fashion, the result is independently verifiable.

The whole block hash could be used as a random number, however, the full hash is extremely large and not practical for calculations meant to be easily verified by others. This calculator's method uses the last 10 hex digits as more reasonable - still a large pseudorandom number with a decimal value between 0 and 1,099,511,627,775.

Math

We use the modulo (%) operation on the hash of a specific future block (that the organizer designates beforehand) to determine the winner:

(last-10-digits-of-block-hash {in decimal}) % (number-of-tickets) = winning ticket number

The winning ticket number output will be from (0) to (number-of-tickets-1), so we must specify that the first raffle ticket number in our list is #0. However, this page's calculator will add 1 to the winning ticket number if you specify the first ticket in the entrant list is instead #1.

There is a small bias to lower ticket numbers with this method if the hex value 0x1000000000 is not evenly divisible by the number of tickets. We remove this bias by considering a very large hash result (such as FFFFFFFFF3) that occurs in the highest incomplete ticket interval invalid, and this page's calculator will report that you must use the next block's hash instead.