Post
Topic
Board Development & Technical Discussion
Re: Random number
by
Taras
on 08/06/2019, 01:44:10 UTC
Chains like Luckycoin and Dogecoin make use of randomness when determining block rewards, so it is possible.

There's a lot of lottery drawings by members of this forum. Instead of selling an item, they sell a lottery ticket to try and win that item. They agree on a way to randomly generate a number, so that the seller can't defraud the bettors. Here's how they solve this problem:

The seller announces they are going to host a lottery with a prize. The lottery will end after a certain bitcoin block in the future is mined; say 1000 blocks from now. After that block number that was agreed upon beforehand is mined, the lottery is over and the winner is announced. The seller announces how the winner will be chosen with this block when the lottery begins. Usually, what they do is, they agree to take the last 4 bits of the hash of that future block. The bettors buy tickets with a unique 4-bit number attached - no two tickets have the same number. If their number is the number taken from the last 4 bits of the block hash, then they won! Nobody can know the hash of the block until it is mined. Even if you are a miner, and you only want to mine a block that ends with your lottery ticket number, making a block that does not end with your lottery ticket number and choosing to discard it for that reason is an immediate BTC12.5 loss. And you probably won't solve another block in time before someone else does anyway, so you couldn't guarantee you will win. The only way to profitably tamper with this drawing without a massive risk (which likely outweighs the value of the lottery prize) is with a successful 51% attack, or perhaps an as-of-yet unknown SHA-256 vulnerability.

You don't have to use 4-bit numbers; you could do 8-bit, or 64-bit, or any number, as long as it cannot exceed the current difficulty target, which is a very massive number. Technically, every block hash is a random number between zero and the difficulty target.