Generating random numbers in Solidity
Some applications might need a random number generator (RNG) to perform specific tasks. There are many use cases where randomness is an essential part. For example, a decentralized lottery requires a random number to select the winner. Randomness can also be used to provide suggestions to the users of the application.
Generating a random number can be tricky in a decentralized system such as Ethereum for various reasons. Such functionality has to be achieved through design workarounds. In this chapter, you will learn how to build an RNG that can be used in your DApp.
Getting ready
It is required to have at least a basic knowledge of writing smart contracts and building DApps using Web3JS. Understanding the implementation of a basic DApp is essential to get more out of this recipe.
For those who are new to this, it is recommended to read through the first three chapters of this book.
How to do it…
- Programs in Ethereum have to be deterministic since they run...