Please note that ExpatTech no longer operates regular office hours, meeting is by appointment only. Please call +36306031104 for details.

ExpatTech Techblog

Peter Todd 2010.09.24. 10:10

Fun with Random - Part 2.

So here we are, we wrote the random function, but it is quite unpractical as it is. Therefore we create a nice little class for it. Basically all the methods of this class need to be static for practical reasons.

After we are done with this, we add a new function to it:

getRandomInt(limit:int), which returns an integer between zero and the given limit. The return value is [0;limit), the limit is not inlcuded in the result set but zero is.

Then we go back to the built-in randomgenerator and compare the results. For this we generate a 100 numbers [0;5) (results can be 0, 1, 2, 3, 4) and we can state that our random function works, if the resulting numbers have the same distribution as using the built-in function.

Results mean how many times the values appeared in the serie.

Built-in results: 14, 19, 18, 18, 31

Own result: 18, 24, 19, 20, 19.

Apparently it works.