Rnd: Difference between revisions

From BR Wiki
Jump to navigation Jump to search
(edit)
 
No edit summary
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
  Rnd([X])
  RND[(<[[numeric expression]]>)]


The '''Rnd''' [[internal function]] returns a random number between 0 and 1. The optional numeric parameter X can be used to reset the random number generator so that the same random sequence can be generated again later.
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====
====Comments and Examples====
Line 10: Line 10:
  00030 NEXT I
  00030 NEXT I


To rescale the random numbers to be between 1 and 100 and make them [[integers]], change line 20 to:
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)
  00020 PRINT INT(RND*100+1)
Line 23: Line 23:
====Related Functions:====
====Related Functions:====
See also the [[RANDOMIZE]] [[statement]].
See also the [[RANDOMIZE]] [[statement]].
<noinclude>
[[Category:Internal Functions]]
</noinclude>

Latest revision as of 00:53, 22 May 2014

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.