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
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.
-
1Thats 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? Commented 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. Commented Nov 30, 2022 at 21:28