Is it possible to generate a random number in Plutus on-chain code? For example, if I would like to implement a smart contract that works like gambling game, where a person deposits ADA and bets on a random outcome and then the contract generates that random outcome to determine if the player won?

1 Answer 1


Is it possible to generate a random number in Plutus on-chain code?

No. On-chain code is deterministic, so there is no way to generate a number on-chian that someone off-chain couldn't predict.

The way around this would be to use an RNG oracle. Essentially outsourcing the generation of the random number to some third party, off-chain. You can then use that oracle's (or multiple oracles') data as an input for any games that needs random values.

  • 1
    Thats what I thought. Rather than using an oracle, would it be possible to simulate a RNG by somehow combining data available in UTXOs? If we would require the input transactions to have random datums and then combine them for all UTXOs would that be sufficiently random? Aug 13, 2021 at 14:27
  • That would create a sort of lottery, where people would be looking for UTxOs that meet a certain requirement, so not exactly an RNG. Nov 30, 2022 at 21:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.