NAME

random - generate random numbers

SYNOPSIS

random(n, flag)
short n;
int flag;

double rnd(n)
short n;

DESCRIPTION

Random seeds (initializes) the random number generator.  If flag is set, a prompt is written to and a value is read from the current file via input(io).  Otherwise the value n is used to produce the seed.  This function implements the RANDOMIZE statement. 

Rnd returns a random number less than one but not less than zero.  First, if n is negative, the magnitude of n is used to produce a seed for the random number generator in the same manner as random.  Second, if n is non-zero, the next random number in the sequence is generated.  Finally, the current random number is scaled and returned.  This function implements the BASIC RND function. 

The random number generator is independent of rand(3) for consistency between systems.  The method is linear congruential.  The numbers are uniformly distributed within the interval.  The period is 231.  The major deficiency of this method is the short period of the low orders bits (vis-a-vis the period of the entire value).  These bits do not participate in the final scaling calculation so they are never returned in any form.  This generator is different from the generator in Microsoft BASIC and is likely superior.  Nevertheless, the user is advised that the quality of the generator can be fully realized only when used in the following manner: (1) The generator must be seeded with a value which is consistently unpredictable such as a combination of low order portions of the time (see time(2)) and the processís ID (see getpid(2)).  Prompting the user for a seed is not recommended.  (2) In order to obtain a value between zero and some value x the expression rnd(1) * x ought to be used. 

SEE ALSO

input(io)
randomize(stmt), rnd(func)
rand(3), time(2), getpid(2) in the UNIX Programmerís Manual

from The Basmark QuickBASIC Programmerís Manual by Lawrence Leinweber