17.07.2013 Views

GWBASIC User's Manual

GWBASIC User's Manual

GWBASIC User's Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

GW-BASIC <strong>User's</strong> Guide<br />

RANDOMIZE Statement<br />

Purpose:<br />

To reseed the random number generator.<br />

Syntax:<br />

RANDOMIZE [expression]<br />

RANDOMIZE TIMER<br />

Comments:<br />

If expression is omitted, GW-BASIC suspends program execution and asks for a value by<br />

displaying the following line:<br />

Random number seed (-32768 to 32767)?<br />

If the random number generator is not reseeded, the RND function returns the same sequence of<br />

random numbers each time the program is run.<br />

To change the sequence of random numbers every time the program is run, place a RANDOMIZE<br />

statement at the beginning of the program, and change the argument with each run (see RND<br />

function).<br />

RANDOMIZE with no arguments will prompt you for a new seed. RANDOMIZE [expression]<br />

will not force floating-point values to integer. expression may be any numeric formula.<br />

To get a new random seed without prompting, use the new numeric TIMER function as follows:<br />

RANDOMIZE TIMER<br />

Example 1:<br />

The internal clock can be set at intervals.<br />

10 RANDOMIZE TIMER<br />

20 FOR I=1 to 5<br />

30 PRINT RND;<br />

40 NEXT I<br />

RUN<br />

.88598 .484668 .586328 .119426 .709225<br />

RUN<br />

.803506 .162462 .929364 .292443 .322921<br />

Example 2:<br />

The internal clock can be used for random number seed.<br />

file:///C|/Documents%20and%20Settings/Lorenzo/Desktop/GW%20Basic/RANDOMIZE.html (1 of 2)28/03/2004 21.29.43

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!