Rnd

From BR Wiki
Revision as of 00:53, 22 May 2014 by Laura (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
RND[(<numeric expression>)]

The Rnd internal function returns a random number between 0 and 1. The optional numeric parameter can be used to reset the random number generator so that the same random sequence can be generated again later.

Comments and Examples

The short program below will generate 10 random numbers between 0 and 1.

00010 FOR I=1 TO 10
00020   PRINT RND
00030 NEXT I

To rescale the random numbers to be between 1 and 100 and make them integers, change line 20 to:

00020 PRINT INT(RND*100+1)

When the optional parameter is used with the RND function, it resets the random number generator so that the same random sequence can be generated again later. This feature should be added outside the loop so that the numbers produced inside the loop will be different. The following program will produce the same set of numbers each time it is run.

00010 LET X=RND(1)
00020 FOR I=1 TO 10
00030 PRINT RND
00040 NEXT I

Related Functions:

See also the RANDOMIZE statement.