Chapter
10
I
BASIC
Keywords
RND
Function
RND[(nurnber)]
Returns a random number in the range
0
and
1.
BASIC uses the current seed when generating a random number
and produces the same sequence
of
random numbers each time
the program is run unless you reseed the random number gener-
ator. Use the RANDOMIZE statement
to
reseed the random
number generator
If
number
is negative, RND starts the sequence
of
random num-
bers at the beginning. If
number
is
0,
RND repeats the last
number generated. If you omit
number
or
specify
a
positive
value, RND returns the next number in the sequence.
Example
PRINT RND(1
1
prints the next decimal fraction in the sequence.
Sample Program
10
FOR
I
=
1
TO
5
20 PRINT INT(RND*l00);
30
NEXT
I
This program produces
5
random integers. Line
20
converts the
decimal fraction returned by RND to
a
real number and trun-
cates the real number
to
an integer.
297