RANDOM range

Outputs a uniform random integer from 0 to the range input (not including the range input). The range input must be a nonnegative integer.

For example, if the input is 10, then RANDOM outputs any of these integers with equal probability: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.

Computers are inherently deterministic, which means that, given a set of inputs, computers always follow a program to produce the exact same output. This makes it difficult for a computer to generate truly random numbers. For this reason, when a computer generates a random nummber, it is often called a pseudo-random number, which means "fake random number". Here's how RANDOM works. Imagine that RANDOM has a giant list of numbers that appear in a predetermined, random-looking order. Each time you run RANDOM, it reads the next number from the list, scales it to the requested range, and outputs the result. If RANDOM always started at the top of this list, then it would always produce the same sequence of numbers each time Logo was run, which wouldn't appear random at all. Of course, RANDOM can't just pick a random place in the list to start, because computers can't create true randomness. To get around this problem, when Logo starts up, it uses the current time to determine where in the list it should start getting numbers from. As long as you start each program at a different time, the random sequence is different, which is usually good enough to simulate true randomness. But if you manage to start two instances of Logo at exactly the same time, then RANDOM would output the exact same sequence of numbers.

Normally, you want RANDOM to output different values each time your program is run. But sometimes you may want to produce the exact same sequence of numbers. In these cases, you can use RERANDOM to reset the location in the list where RANDOM gets its next number from.

See Also

SourceForge.net Logo