How to Achieve Randomness in a Smart Contract
Generating randomness on-chain is notoriously hard. You need a number that’s unpredictable before it’s revealed, unbiased during its generation, and verifiable afterward. To make things even more challenging, nodes of the network have to generate and agree on random numbers in a distributed and decentralized manner. With these nearly opposing constraints, traditional random functions (like Math.random()) aren’t an option.