The importance of REAL random results
I was wondering if functions in various languages used to return random values, such as AS2 Math.random() or Php rand() are returning real random values or just a sequence of numbers someone can predict.
So I asked the question to someone that is facing this problem for a long time: Matt from CasinoInLinea.
That’s what he said:
Random results are very important in many computer applications. From online casino games, through video arcades, image processing to data security & encryption software and many other types of applications.
Since computers are 100% predictable: The same actions, performed at a specific order, will always lead to the same results. This means that generating true random numbers is not an easy task. For a function to produce a random number, one of the variables must have a different value every time.
A series of numbers is truly random if it completely unpredictable. In other words, if we have absolutely no way of knowing what the next number is in a series of N numbers, then the series is completely random. On the other hand, if we can determine the next number according to a specific formula, (i.e. Fibonacci, a linear or parabolic function etc), then the series is a function, and is not random at all. As odd as it may seem, computer functions also have interim statuses. A function can be highly random, (i.e. it’s difficult BUT POSSIBLE to predict the next number). It all depends on the capability of the RNG (random Number Generator) algorithm.
Applications like online casino software and security related programs (i.e. password generators, data encryption and more) demand the highest randomness possible. Imagine a roulette table in which a player can predict where the ball falls next, or a password generating software that generates predictable “random” passwords. Both scenarios present a major security breach for the software operators.
So how do random functions produce random numbers? Here are a few common ways:
The computer’s clock
That’s the easiest, cheapest and least secure method. The computer clock offers an ever changing value that always increases with time. Therefore, it is possible to integrate the absolute time value into the random function to produce random results. (The time value is a 2 * 16 bit, double word binary value) that contains years, months, days, hours, minutes & seconds).
Random keyboard or mouse sequence
Some applications (e.g. client-based password generators) resort to a more creative way of producing a random value. They ask the user to provide a sequence of keyboard strokes or a random mouse curosr movement over a specific screen area (or a combination of both). The keystrokes and/or mouse movements are then compiled to a series of values, which are then compiled to a single, random number. This method is excellent at giving the user a distinct sense of control. Its major drawback is that it cannot be used in automated processes (e.g. command line batch executions).
Hardware-based RNG
For applications where randomness is crucial, such as online casino software or encryption software, RNG extension cards can be installed on server machines. These offer faster, more secure random numbers, which are virtually inpredictable. When randomness is of outmost importance, Hardware based is the best solution, although the most expensive one.
Having said all that, when you develop your next computer game, be it browser or client based, you should not worry too much about random numbers – feel free to use your development environment’s native random functions (which probably use the computer’s clock). The gaming experience is unlikely to be affected by it.
If you’re still serious about random numbers, and demand nothing but the best, this website provides more in-depth information about using random number genreators.
Tell me what do you think about this post. I'll write better and better entries.
8 Responses to “The importance of REAL random results”
Leave a Reply


(15 votes, average: 3.67 out of 5)
Great post, E. I was wondering about this recently when making an AS3 flash game, whether using Math was enough. Is there a simple way to “seed” Math.random so that (as Matt said) “one of the variables has a different value every time.” I’ve been thinking a custom solution might actually cut down on processing time (which I’ve been needing somewhat in my game loop).
ive always wondered how exactly they have a random function in flash cause its programmed into it which means it cant be random o.O
Wierd…
I didn’t know they used time based random too… that was my idea… lol
I think the current percent of cpu and ram being used is also used to generate (somewhat) random numbers.
good post :)
Even more random are nature based random number generators. Check out the ones online that generate from lava lamps, radio waves, etc
To make a random number in flash, they don’t actually use a pure random number, but a pseudo-random number. It is governed by a series of incredibally complicated equations which make it almost random. You can fid out more on wikipedia:
http://en.wikipedia.org/wiki/Pseudorandom_number_generator
My math teacher once said me that is IMPOSSIBLE to a computer generate a TRUE random number, becouse of a huge amount of factors. He also told me that a computer does not have a brain (something organic, that think emotionally), so it cannot do actions purely random, only mathematically stated actions.