For fun and practice I want to build a contract that picks a number between 1 and 100, and give a sender their ether back if they can guess it in 7 tries.
I'm quite sure I don't understand enough to know if this is possible, but that's my purpose for trying.
My first snag was generating a "random" number. There's an op-code for blk_nonce which sounds promising, but how is that op-code even possible?
Is that the nonce of the last block? It can't be the nonce of the "current" block -- unless it's the nonce for just the miner running this script, which might be different from miner to miner. But wouldn't that cause a blockchain fork if, for example, a script did something like "if blk_nonce is even then send ether to A, else send ether to B" ?
Clearly there's still big holes in my full understanding of all this. Basic questions for now:
- What is blk_nonce exactly?
- What other way might there be to get a secret random-like number?