Commodore 64 User Manual page 59

Hide thumbs Also See for 64:
Table of Contents

Advertisement

NEW
10 F
O
R
X = 1 T
o
1e
IF YOU LEAVE OUT THE COMMA YOUR LIST
20 PRINT RND ( 1)
, OF NUMBERS WILL APPEAR
30 NEXT
AS 1 COLUMN
After running the program, you will see a display like this:
.789280697
.664673958
.256373663
. 0123442287
.682952381
3.90587275E-04
.402343724
. 879300926
.158209063
.245596701
Your numbers don't match? Well, if they did we would all be in
trouble, as they should be completely random!
Try running the program a few more times to verify that the results are
always different. Even if the numbers don't follow any pattern, you
should start to notice that some things remain the same every time the
program is run.
First, the results are always between 0 and 1, but never equal to 0 or
1 . This will certainly never do if we want to simulate the random toss of
dice, since we're looking for numbers between 1 and 6.
The other important feature to look for is that we are dealing with real
numbers (with decimal places). This could also be a problem since
whole (integer) numbers are often needed.
There are a number of simple ways to produce numbers from the
RND function in the range desired.
Replace line 20 with the following and run the program again:
20 PRINT 6*RND(1),
RUN
3.6056 3664
4.53660853
5.47238963
8. 40850227
3.19265054
4.39547668
3.16331095
5.50620749
9.32527884
4.17090293
49

Hide quick links:

Advertisement

Table of Contents
loading

Related Products for Commodore 64

Table of Contents