Secure lottery function / Random Number Generation

Is it possible to create a lottery application to run an online raffle? For specific products/prizes etc

If so , would the ICP be susceptible to bots purchasing all tickets like you would see online these days in many different online purchases.

Thanks in advance.

1 Like

I found these 2 great articles on something similar but built on ethereum which comes with its drawbacks eg gas fees and inability for the draw function to be called automatically.

Is random number generation easier on the ICP?

I am wondering how different would such an application look like on ICP written in Motoko or could you run this sample code directly in a canister?

Chainlink also do something similar here

You can explore using the Random module in the base library: Random :: Internet Computer

There’s some discussion on using it in this thread here: https://forum.dfinity.org/t/usage-of-random-base-package/1668/4?u=ori

2 Likes

Thanks.

Complicated stuff for a non developer but I think I have a general idea of how it functions on the ICP now, but developing it is another story altogether.

If there were any tutorial’s I’d love to give it a shot. Maybe something that can follow in the future document releases and demo’s.

Will it be possible to verify the randomness of generated numbers? In this instance , verify raffle results or the entrants in a raffle?

Will this information be viewable on the block explorer/dashboards?

I think you should be able to securely a share strong hash of the entropy blob which is providing the randomness.

Sharing the blob after, users could verify the results, knowing you used the blob you said you did.

OR, you could hash the blob, generate a number, hash the number concat the two as a string and share the hashed result of that.

I think I follow you on the second option.

So blob creates a random hash…how would you match a winner or multiple winners in a case like this? Some comparison of their wallet address compared to the created hash?

Example being , 500 entrants with 10 winners…I can’t wrap my head around how the blob would allow the winners to be verified.

Canister’s would also need to be able to be viewed to verify authenticity.

if you’re familiar with something like minecraft, the blob would be the “seed” the random number generator uses to create random numbers. It’s completely deterministic, but appears random.

Sharing the seed with someone would let them cheat the system, since they’ll always know what number will be pulled.

However, if you share the hash of the seed, it is very very hard to figure out the seed from the hash.

So, you can give them the hash of the seed, which they can later use to verify you used the seed you said you did.

  1. Give them the hash of the seed.
  2. Run the generator.
  3. Give them the seed

User then checks the hash of the seed, and runs their generator with the seed to get the number! Woo!

1 Like

This would be the authenticity part of the equation correct? Proves the random winning number was indeed created randomly

Yup thats correct! There are a bunch of ways to go about this.

1 Like

Thanks for that…very much appreciated!

Beginning to wrap my head around it now I think :laughing:

Any dev’s looking to work or test a project like this…please hit me up!

Would love to get some sort of prototype of this functionality