This article was first published on Chainlink
Random number generation (RNG) cannot be done natively in Solidity. To generate a truly verifiable random number on a blockchain, a smart contract must send a seed to an off-chain resource like an oracle, and the oracle must return the random number along with verifiable proof back to the smart contract, proving the random number was generated using the seed. With Chainlink VRF now live on Ethereum mainnet, developers can easily generate random numbers in Solidity in a safe, secure, and verifiable way. In this technical article, we’ll show you how to generate a random number in Solidity using Chainlink VRF.
Examples of generating safe random numbers in your smart contracts can be found in the Chainlink Documentation. Here is a Remix example of blockchain random number generation on the Kovan testnet for those looking to test it out now. Just remember to follow the request and receive methodology and fund your smart contract with LINK.
High-Level Overview of Chainlink VRF
Chainlink VRF (Verifiable Random Function) is a provably-fair and verifiable source of randomness designed for smart contracts. Solidity developers can use it as a tamper-proof random number generator to build safe and reliable smart contracts for Ethereum applications that rely on unpredictable outcomes.
The first step in generating a random number in Solidity using Chainlink VRF is to determine a seed. It is extremely important to choose a seed that is difficult to influence or predict. If someone can influence or predict the seed, they could in theory try to collude with the oracle performing the request for randomness to give themselves a favorable result. Because of this, it’s advised to not use values derived from the state of the blockchain such as the block height or block timestamp.
This seed is then sent in a request to ...
To keep reading, please go to the original article at: