Search code examples
blockchainethereumsoliditysmartcontractsether

Why is it not possible to directly choose a random element in solidity?


We don't have access to random number generator? if you have to pick somebody randomly we do it using pseudo random generator.


Solution

  • You can't create truly random numbers 'cause Blockchain is a deterministic system, so we must ensure that every node must give the same random number to be sure that every node can mint the same block.

    Determinism is important because no matter where the smart contract code executes, it is critical that it produces the same result every time.

    you can find some pseudo random generator through chainlink's contract: https://chain.link/chainlink-vrf