|
Designed for computer science instruction, Turing is simply the easiest, most fun, and most effective way of teaching programming concepts. |
|
Quick Links |
||
randint, rand,
or any subprogram from the Rand module,
Turing performs a fairly complex calculation on the old
random number seed and produces a new one. It
then takes this new seed and uses it to produce
the number requested.
For randint and Rand.Int,
it essentially does a
mod of the new seed with
the range of values for specified in the randint
call. For rand and Rand.Real
it returns a value that is between
0 and 1 by dividing the new seed by the highest possible
value for the seed. The next time a random number is
requested, this operation is repeated. Each time a new seed
is created.
Note that there is no random element here. If you have a given seed when making a request for a random number, the next seed will always be the same. In other words, random numbers aren't random. It's just that the user doesn't know what the next number will be. For this reason, computer scientists call them pseudo-random numbers.
The only candidate for that is the system time. (Which is what almost every random number generator uses to create a seeds. Each time a Turing program executes, Turing takes the current time (in number of seconds since Jan 1, 1970) and manipulates the bits to make the the seed for the random number generator.
You can see this in effect if you run the program
for i : 1 .. 5
put Rand.Int (1, 100)
end for
several times in a row (press F1 multiple times). If you are running
it more than once a second then you will see the same random number
sequence show up. Each second the sequence will change as Turing
generates a different seed when the program is executed.
Rand.Reset.
Note that you will get the same sequence of random numbers, not the
same random number each time you call Rand.Int.
The Art of Computer Programming, Volumes 1, 2, 3
by Donald E. Knuth
Published by Addison Wesley
In my humble opinion, this series of books are perhaps the quintessential
reference work for computer scientists.