NAME

rnd - random number generator

SYNOPSIS

v = rnd[(NumExpr)]

DESCRIPTION

Rnd generates random numbers.  The same sequence of random numbers is generated each time the program is run unless the random number generator is reseeded (see randomize).  Reseeding the generator may also be done by calling the rnd function using a negative NumExpr.  A given NumExpr will always generate a particular sequence.  This sequence is not affected by randomize. 

If NumExpr is positive or not included, rnd(NumExpr) generates the next random number in the sequence.  If NumExpr is zero, rnd(NumExpr) repeats the last number generated. 

EXAMPLE

The program
	for j = 1 to 3
		print rnd(j);	' x>0
	next j
	print
	a = rnd(-9)		' x<0
	for j = 1 to 3
		print rnd(j);	' x>0
	next j
	randomize 200		' randomize
	print
	a = rnd(-9)		' x<0
	for j = 1 to 3
		print rnd;	' same as x>0
	next j
	print
	print rnd(0)
produces
	 .081268310546875  .985595703125  .004913330078125
	 .3192138671875  .47607421875  .99713134765625
	 .3192138671875  .47607421875  .99713134765625
	 .99713134765625
The first row of results shows three random numbers, generated using a positive NumExpr.  The second row of results shows three random numbers, generated using a negative NumExpr in line 40.  The third row of results is identical to the second line. 

In line 80, the random number generator is reseeded using the randomize statement; in line 90 it is reseeded again by calling rnd with the same negative value we used in line 40.  This cancels the effect of the randomize statement.  The last number printed is the same as the preceding number.  In line 95, rnd is called with an argument of zero. 

SEE ALSO

randomize

from The Basmark QuickBASIC Programmer’s Manual by Lawrence Leinweber