Leet More 2010 Lottery writeup

Warning! There are at least two ways of solving this task.

Look at HTML sources. Try to find web-framework running the lottery.
It is “Nitrogen”- Web Framework for Erlang. To generate random numbers Erlang have module random.
To get random Int we have function  uniform(MaxInt)->Int

So example of code for generating number for lottery is

But for every request Nitrogen would generate new PID and random:unifom(X)  generates the same sequence for each PID if X is equally because of function definition:

So we need to seed our random generator. Think about what options we can use.  Time? No (you may try, it is easy to check). Participant? Yep, let’s try.

Here sources of functions that we need:
Default seed.

Functions of Users seed.

And finally pseudo random generation

I think this code is easy understandable. Based on this algorithm we can determine that task for generating random numbers used this code

or

Where Users = Participants-1.

PS. Another brilliant way that doesn’t require Erlang knowledge (based on pure math) was posted by “Worawit”. You can read it here

Leave a Reply

Your email address will not be published.