I know that it's not possible to have a completely 'safe' random generator on block chain.

But still wondering how safe it would be if I use a combination of methods like now() and transaction_size() to generate a random number generator. How easy would it be compromised, would it be easy to manipulate the number?


You should never use now() to seed the random number generator because the blockchain generates a block every 0.5 second which means an attacker can write a smart contract to predict the result of a future block.

| improve this answer | |
  • I was thinking it was millisecond so it would be quite unpredictable. However just checked the API reference and it was "second". So this wouldn't work. Thank you very much! By the way, is there a way to get the number of trasactions in the current block? If so, would this be a good resource for random number generation? – daniaoren Sep 14 '18 at 9:37

There is an official answer to this question :) https://developers.eos.io/eosio-cpp/docs/random-number-generation

| improve this answer | |
  • 1
    Thank you very much, I've checked this doc before. This method is the most fair and secure one, however it is a bit unrealistic when you want to use it in games. It's just pretty hard to ask users to come back and 'reveal' their securets. – daniaoren Sep 11 '18 at 10:40
  • You dont need their secrets. All you need is a source of randomness. Dont you? – Vasiliy Bondarenko Sep 12 '18 at 13:30

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