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?


2 Answers 2


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.

  • 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
    Commented Sep 14, 2018 at 9:37

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

  • 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
    Commented Sep 11, 2018 at 10:40
  • You dont need their secrets. All you need is a source of randomness. Dont you? Commented Sep 12, 2018 at 13:30
  • This link is no more valid. Anybody has any other reference to generate the random numbers?
    – Varsh
    Commented Dec 9, 2020 at 8:11

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