Click 'Run' to go.
The first thing to know about random numbers in most common computer languages is that they are not random. They are calculated using a preset method. However, if calculated repeatedly, the sequence of numbers produced appear to be randomly distributed, at least if you do not look too deeply. So this method works for simulating random numbers in many situations, notably games.
Computer languages often contain a function that outputs a random number. Although parentheses for input usually follow the random function name (like they do for any function), often the parentheses are left empty, since an input could have no effect on the output if the output is to be random.
In our demo here the name of the random function is rnd. It produces a random number between 0 and 1. Well, it almost does that; it never will really produce a 1, but it will get very close to 1. So its range would more correctly be stated as from and including 0 up to but not including 1. Or you might say from 0 to 0.99... . As it turns out, this is sufficient for producing random numbers over a wider range using additional mathematics. This is shown in the article titled 'Random over a range'.
Click the run button on this demo several times and note the group of numbers that is produced from all the outputs. All the numbers will be between 0 and 0.99... .
A random number generator as found in most computer languages will produce the same sequence of seemingly random numbers every time the program is run. That is because the random numbers are actually calculated using a method that starts and proceeds the same way every time the program is run.
If you want to get a different sequence of random numbers, the trick is to change the starting parameters for the random number calculating method. This is called seeding the random number generator. Most computer languages contain commands that let you seed the random number generator.
Here would be the flowchart for this simple output:
In an imaginary computer language this could look like the following:
Suggested next article:
The following article is related to this demo: