Bitcoin Stack Exchange is a question and answer site for Bitcoin crypto-currency enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to create a transparent gambling/lotto site and use the block chain as entropy for lotto numbers, dice rolls, that kind of thing. Would the transaction hash of the latest transaction be the best way to do this? How often are transaction hashes created? How would you, programmatically, access them?

share|improve this question

closed as off topic by ripper234, eMansipater, Chris Acheson, Dori Sep 21 '11 at 0:51

Questions on Bitcoin Stack Exchange are expected to relate to Bitcoin within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

This feels slightly off topic. – ripper234 Aug 30 '11 at 23:06
why off-topic? from the FAQ: " practical, answerable questions based on actual problems that you face". Seems pretty on-topic unless I am missing something. – browep Sep 1 '11 at 21:01
because it would be impractical to use Bitcoin for entropy in a gambling site. There are other easier ways to do this today. – ripper234 Sep 2 '11 at 6:55
wouldn't "impractical" be up to me? The question is not about how to implement a gambling site, it's about using the blockchain as entropy. The use of it is irrelevant, it's still a valid question. And doesn't solve all my problems. – browep Sep 2 '11 at 21:08
It may be a valid question, but it's not a particularly bitcoinish one--smells more like programming technique to me, which should go on Stack Overflow. – eMansipater Sep 6 '11 at 20:23
up vote 6 down vote accepted

The Bitcoin Lottery used an SHA256 hash of the two most recent blocks to generate random data and to my recollection there were not too many complaints about that method they chose. In any case it's only good for 256 bits of questionably random data every 10 minutes (20 if you don't reuse blocks) so there are probably better entropy sources, such as the setup they've built over at

share|improve this answer
thanks. seems like a good place to start. – browep Sep 1 '11 at 4:13
And here, "questionably random" means that given a suitably large reward and a suitably motivated miner this would absolutely be gamed. – eMansipater Sep 6 '11 at 20:25
Actually a correct random implementation with Mersenne Twister would suffice. If people get paid, they don't care much about how do you generate the numbers. Joe Six Pack wants his price, not to know. – flaab Oct 25 '12 at 8:39

If I may answer with my stack overflow hat on...

Here's how I'd draw a random number in way that no participant can influence the result of.

Invite each player to pick a random number, x, and publish the hash(x). Once each hash has been published, each player should then reveal their x. With those x's, add them all together and hash the result. Use that final hash as the random value.

UPDATE: To work around the attack described in the comment below, use two rounds.

  1. Each player selects a randon number, x, and reveals hash(x).
  2. When all hashes have been revealed, each player reveals x.
  3. All x's are combined and hashed. y=hash(all x)
  4. Each player selects a new random number, z, and reveals hash(y+z).
  5. When all of the second round of hashes have been revealed, each player reveals z.
  6. All z's are combined and hashed. The result is used as the random value.

If the player has a prepared hash collision, they could only use it to select their prefered y value. This doesn't help because they would now need a way to find a collision where both inputs have the same prefix (y) which won't be known in advance. If you can do that in a timely manner, we all need a new hash function.

(I welcome comments. Its possible I've missed something else.)

share|improve this answer
An attacker could find a hash collision where hash(a) = hash(b), publish the common hash value, and then observe the other players' revealed numbers before choosing whether to reveal a or b. – JGWeissman Sep 16 '11 at 22:26
@JGWeissman - I missed that. Thank you. I've updated the protocol to work around that issue. (Or maybe I've made it worse.) – billpg Sep 22 '11 at 18:37
Now an attacker with a hash collision on a and b can reveal in step 4 that hash(y+z) is the common hash of a and b, and then in step 5 choose to reveal either that z = a-y or that z = b-y. – JGWeissman Sep 22 '11 at 19:51
So, in step 4, require also that each player reveals hash(z). – JGWeissman Sep 22 '11 at 19:52
Ah, by + I meant concatenation, rather than addition. Anyway, I suggest we move this discussion to a different SE. I've taken the liberty of opening this Q.… – billpg Sep 23 '11 at 23:47

Only sort of. The transaction hash is specifically chosen because it is smaller than some number X (--> difficulty factor), so it isn't fully random. However, it has a lot of entropy in the sense that it contains input from a lot of different, not predictable transactions. So you could use this hash as a seed for your RNG.

If you just want to generate lotto numbers and dice rolls, I'd say it's more important that you find a good random number generator (RNG) - you won't reseed that often anyway.

If you wanted to use the hash as the random number directly, there's a problem: you only get one hash every ~10 minutes. Not all that many random numbers.

share|improve this answer

You could scrape data from to get the hashes of transactions that had just been submitted. It wouldn't super easy to do, but it'd be a constant source of fairly random data.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.