Feasibility of smart contract idea: Randomized payout when sending funds


I’m watching the Plutus pioneers videos and have some q’s on feasibility of what’s possible. Would love some feedback on how some of this might be implemented or if it isn’t possible:

I’d like to create a contract which behaves like this:

  1. Anyone can send funds to an address
  2. Whenever the address receives funds, a random number is generated, and if the random number is below a certain threshold (say 1 out of 1000 times) the amount of funds in the address is sent back to the person who made the tx.

So some more specific q’s:

  • Can you trigger a contract by simply sending funds to an address? Or do you have to call a function within the contract similar to what’s in the #2 Plutus pioneers video with the “give” function
  • How do you generate random numbers in a contract? I’ve read a bit on other smart contracts and it seems you might need an oracle to do this… how would this work in a Plutus contract?
  • Assuming #1, can you have a contract send back funds to the change address (is that the right term?) of someone who sends funds to a script?



PRNG on-chain is going to be a mix-in input that selects from a predetermined distribution at best. All smart contracts need to be deterministic so “random” anything isn’t a supported use case.

Unfortunately I have a similar use case for my project. What I ended up doing was randomly generating the values off-chain and supplying them as inputs. The on-chain portion validates three things:

  • That each value is within the appropriate range
  • That no two values are the same
  • That no more than one value is at the maximum extent of any range

My off-chain codes follows the same rules but validating on-chain as well helps prevent manipulation and abuse.