Chapter
10
I
BASIC
Ke.ywords
RANDOMIZE
RANDOMIZE
[number]
Function
Reseeds the random number generator.
Number
may be an integer, or single- or double precision num-
ber.
If
you omit
number,
BASIC suspends program execution and
prompts you for
a
number before executing RANDOMIZE:
Random Number Seed (-32768 to
32767)7
If
the random number generator is not reseeded, the RND func-
tion returns the same sequence of numbers each time it is exe-
cuted. To change the sequence of random numbers every time
the RND function
is
executed, place
a
RANDOMIZE statement
before the RND function.
You can use the TIMER function to ensure that the random
number generator
is
reseeded with
a
different value each time
BASIC executes the RANDOMIZE function. For example, the
statement:
RANDOMIZE TIMER
uses the value returned by TIMER as the seed. TIMER returns
the number
of
seconds that have elapsed since midnight or the
last system reset. Because the seconds are constantly changing,
number
has
a
different value each time BASIC executes this
st at ement
.
Sample Program
10
CLS
20 RANDOMIZE
TIMER
30 INPUT
"PICK
A
NUMBER BETWEEN
1
AND
100";
A
40
B
=
INT<RND*100)
50
IF
A=B
THEN
80
60
PRINT
"You
lose,
the answer is"B;"--try
a ga
i
n
.
"
70 GOT0 20
80
PRINT
"You picked the right number
--
you
win."
285