I create a random number starting from block.coinbase, block.number and block.timestamp, then I determine some probabilities. Is it correct or there is a better way?
bytes32 bHash = keccak256(block.coinbase, block.number, block.timestamp);
if (bHash[30] == 0xFF && bHash[31] >= 0xF4) {
//one chance on 5000
//do something
} else if (bHash[28] == 0xFF && bHash[29] >= 0xD5) {
//one chance on 1500
//do something
} else if (bHash[26] == 0xFF && bHash[27] >= 0x7E) {
//one chance on 500
//do something
} else if (bHash[25] >= 0xF4) {
//one chance on 20
//do something
}
As suggested in the answer, the best way to do is: generate randomness out of ethereum, then commit to it, then reveal when everyone has played/commited.
– Distic Sep 06 '17 at 07:03