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.
10 Responses to “The importance of REAL random results”
Leave a Reply
- Get up to $100,000 for your next Flash game with Mochi GAME Developer Fund
- Create a dynamic content animated footer ad for your site in just 9 jQuery lines – 17 lines version
- Sell sitelocked version of your Flash games and even .fla sources to Free Online Games
- Protect your work from ActionScript code theft with SWF Protector
- Create a dynamic content animated footer ad for your site in just 9 jQuery lines
- Understanding Box2D’s one-way platforms, aka CLOUDS
- Triqui MochiAds Arcade plugin for WordPress upgraded to 1.2
- Box2D Flash game creation tutorial – part 2
- 11 Flash isometric engines you can use in your games
- Monetize your Flash games with GamesChart
- Create a Lightbox effect only with CSS - no javascript needed
- Flash game creation tutorial - part 1
- Create a Flash Racing Game Tutorial
- Flash game creation tutorial - part 2
- Make a Flash game like Flash Element Tower Defense - Part 2
- Flash game creation tutorial - part 3
- Make a Flash game like Flash Element Tower Defense - Part 1
- Create a flash draw game like Line Rider or others - part 1
- Triqui MochiAds Arcade plugin for WordPress official page
- Create a flash artillery game - step 1
- Flash game creation tutorial – part 5.2 (4.88/5)
- Create a flash artillery game – step 1 (4.79/5)
- Create a Flash Racing Game Tutorial (4.76/5)
- Create a flash artillery game – step 2 (4.74/5)
- Create a survival horror game in Flash tutorial – part 1 (4.73/5)
- Creation of a Flash arcade site using WordPress – step 2 (4.73/5)
- Flash game creation tutorial – part 2 (4.71/5)
- Flash game creation tutorial – part 1 (4.70/5)
- Create a flash draw game like Line Rider or others – part 1 (4.69/5)
- Creation of a platform game with Flash – step 2 (4.68/5)


(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.
I w
I was faced with the opposite problem. The flash Math.random function cannot be “seeded”, and I needed a peudo random function that will always return the same results given the same seed.
Fortunatly, gskinner came up with a solution in AS3 using the perlin noise seeded random function?
It’s all there :
http://www.gskinner.com/blog/archives/2008/01/source_code_see.html