Jump to content

Futurebasic/Language/Reference/random

From Wikibooks, open books for an open world

Syntax

[edit | edit source]

RANDOM[IZE] [expr]

Description

[edit | edit source]

This statement "seeds" the random number generator: this affects the sequence of values which are subsequently returned by the RND function and the MAYBE function. The numbers returned by RND and MAYBE are not truly random, but follow a "pseudo-random" sequence which is uniquely determined by the seed number. If you use the same seed number on two different occasions, you'll get the same sequence of "random" numbers both times. For example: CLS FOR i = 1 TO 2

 RANDOMIZE 325
 FOR j = 1 TO 10

PRINT RND(50),

 NEXT
 PRINT

NEXT The program above seeds the random number generator twice with the same number (325). If you run this program, you'll find that it produces the same sequence of 10 random numbers after each seeding. Seeding the random number generator with a pre-specified number can be useful in cases where you specifically want to produce a repeatable sequence of random numbers. In most cases, however, you will probably prefer a sequence that is unpredictable. In that case, you should omit the expr parameter. When you execute RANDOM without any expr parameter, the system's current time is used to seed the random number generator. Since the system clock changes very quickly, it's essentially impossible to predict what value will be used as the seed-this is the best way to get the "most random" random numbers. Normally, you will execute RANDOM only once in your program, unless you wish to repeat a specific sequence of random numbers. If you don't execute RANDOM at all, the random number generator is seeded with the current tick count. Remember that re-seeding with the same number will cause your program to generate the same sequence of random numbers each time it's run.

See Also

[edit | edit source]

RND; MAYBE