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.

  • 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 at 9:37

Did you know you are free to use boost library, as it's included into EOS? In your smart contract you can use boost/random to get a profound random functionality you require.

  • Thank you very much! This is a pseudo-random number generator, so it comes out with the same result with the same input. I know it is impossible to generate real random numbers on computer without random devices. I'm just seeking a way to create random numbers that is very very hard to predict. So I can use it in games. – daniaoren Sep 11 at 10:46

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

  • 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 at 10:40
  • You dont need their secrets. All you need is a source of randomness. Dont you? – Vasiliy Bondarenko Sep 12 at 13:30

I use boost/random and now() to generate random Numbers for the specified range, and I'm not sure the mining pool can fool it?

  • Just checked the API, the now() returns the time in seconds. So basically one can easily predict the result by timing the transaction and get the number they wanted. – daniaoren Sep 14 at 9:39

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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