roger_ardouin
7 days ago  Karma: 5
How can I generate a truly random number in a smart contract?

How can I generate a truly random number in a smart contract?

en
#smart contracts
#ethereum
roger_ardouin
7 days ago  Karma: 5
How can I generate a truly random number in a smart contract?

How can I generate a truly random number in a smart contract?

en
#smart contracts
#ethereum

4 ANSWERS
anthonygriffiths47
7 days ago Karma: 155

I don't think it's possible to generate a truly random number on the blockchain. The closest you can get is a pseudo-random number, computed using Ethereum's keccak function.

https://cryptozombies.io/ has a good example. I encourage you to have a look.

I don't think it's possible to generate a truly random number on the blockchain. The closest you can get is a pseudo-random number, computed using Ethereum's keccak function.

https://cryptozombies.io/ has a good example. I encourage you to have a look.

brandon.pearson1011
7 days ago Karma: 1449

Seeding the hash function with some data like block's timestamp, a nonce, or something similar is a good approach only when stakes are not so high. But, if the stakes are high, a miner can try to manipulate the outcome. I think the most secure option is to use an oracle.

Seeding the hash function with some data like block's timestamp, a nonce, or something similar is a good approach only when stakes are not so high. But, if the stakes are high, a miner can try to manipulate the outcome. I think the most secure option is to use an oracle.

kaijchang2
7 days ago Karma: 19793

Using block info as a random value generator is only secure as long as the value of the decision decided by it doesn't exceed the value of mining a block (3 Ether). You could theoretically use an oracle, but that brings other risks like trusting the oracle.

Using block info as a random value generator is only secure as long as the value of the decision decided by it doesn't exceed the value of mining a block (3 Ether). You could theoretically use an oracle, but that brings other risks like trusting the oracle.

eliesteinbock
7 days ago Karma: 10

Depending on the situation, you may be able to rely on user data that is submitted hidden and later revealed. This could be based on many users and when you combine it with the hash of the block, it can provide randomness.

One issue that lottery type games have encountered is that a smart contract can call your random function, and then check if it's won or not. If it hasn't it will revert the transaction.

Depending on the situation, you may be able to rely on user data that is submitted hidden and later revealed. This could be based on many users and when you combine it with the hash of the block, it can provide randomness.

One issue that lottery type games have encountered is that a smart contract can call your random function, and then check if it's won or not. If it hasn't it will revert the transaction.

Earn tokens by posting and answering questions about blockchain!
Karma to eth
YOUR ANSWER