Skip to main content
18 votes
Accepted

How can I generate random numbers inside a smart contract?

One method of achieving pseudo-randomness can be accomplished by comparing hashes // variable to get result from hashing all players hashes and secrets checksum256 result; // hash the contents in ...
Sandwich's user avatar
  • 384
15 votes

How can I generate random numbers inside a smart contract?

Randomness without risk of anyone "knowing" it requires a three step process: both parties commit hashes of secrets hash(secreta) and hash(secretb) both parties reveal secrets secreta and secretb ...
bytemaster's user avatar
  • 1,434
6 votes

Random number generation

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 ...
Jeff Zheng's user avatar
4 votes

How can I generate random numbers inside a smart contract?

EOS Knights implements a random generator, which, at the moment, is MIT-licensed: // Linear Congruential Generator class random_gen { private: static random_gen instance; const uint32_t a = ...
confused00's user avatar
  • 5,554
4 votes

How can I generate random numbers inside a smart contract?

According to this github issue, using pseudo-random number generation libraries inside the contract would break the consesus because the execution of smart contracts must be deterministic. That means ...
Jordi Goyanes's user avatar
1 vote

Validation for contract which has data which varies

If you need information in your contract that changes over time, such as real-world pricing information, you should have an action on your contract that allows you to inject the information as part of ...
John Haager's user avatar
  • 1,844

Only top scored, non community-wiki answers of a minimum length are eligible