Personal Computer News


Microsoft Basic Random Numbers

 
Published in Personal Computer News #047

Microsoft Basic Random Numbers

Nearly every Microsoft Basic program that owners write utilises a random number generator. Often it is used in different parts of the program. In Microsoft Basic, its use generally takes the form:

X=INT(100*RND(1)+1) where 100 is the range

This is rather cumbersome and can be improved by defining the expression as a function:

10 DEF FNR(X)=INT(X*RND(1)+1

To obtain random numbers, simply use R=FNR(100). Throwing two dice can be reduced to D=FNR(6)+FNR(6). The method is not only shorter, but faster as well.

Paul Roper
Gosport, Hants

Paul Roper