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.
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 .99713134765625The 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.
from The Basmark QuickBASIC Programmer’s Manual by Lawrence Leinweber