onflow / random-coin-toss

An example repo demonstrating safe use of onchain randomness
The Unlicense
5 stars 4 forks source link

Add example random in range function #21

Closed sisyphusSmiling closed 1 month ago

sisyphusSmiling commented 1 month ago

Description

Recent discussion in https://github.com/onflow/docs/pull/902 reveals the need for a safe demonstration of generating a random number in a range. @tarakby listed a couple of feasible approaches that can be taken for this implementation. This functionality can be added to the existing CadencRandomConsumer.sol base contract for easy consumption in the context of randomness.

This implementation should then be added to the docs as reference.

tarakby commented 1 month ago

Very cool! Thanks for taking the initiative to add a reference method for developers, and very quickly after the feedback 🙏🏼

Before I look at the solidity implementation, I was wondering if an alternative "simpler" way could work: what if we update the EVM arch of revertibleRandom to export the modulo behaviour from Cadence. I explain:

sisyphusSmiling commented 1 month ago

I think this is the ideal solution @tarakby. It would be much easier to implement a "random range" function from the EVM side if it was simply abstracted in Cadence Arch. I'd be curious to hear thoughts from those more familiar with Arch precompile calls - cc @ramtinms @m-Peter

While I'm not deeply familiar with Cadence Arch, I'm fairly sure the change would require a network upgrade with the next one slated in the order of months. If that is in fact the case, IMO we should still provide some workable solution for acquiring a random number in range which would fall in the realm of a solidity implementation.