! dice rolling demo of standard Basic functions

! RND and INT(...), and instructions RANDOMIZE, SOUND and PAUSE

 

PRINT "press command key and period (.) to quit"

RANDOMIZE

! to get different pseudo-random sequence each time run

! check by deactivating it and comparing run to run output

DO

LET w = RND

! 0 <= w < 1 where w is a decimal number

LET x = 6*w

! 0 <= x < 6 where x is a decimal number

LET y = x + 1

! 1 <= y < 7 where y is a decimal number

LET z1 = INT(y)

! 1 <= z1 <= 6 where z is integer part of y left of decimal pt.

! or combine all together

LET z2 = INT(6*RND + 1)

IF z1 = 1 AND z2 = 1 THEN

SOUND 1000, 0.25

SET COLOR "red"

PRINT "Snake Eyes! [*][*]"

SET COLOR "black"

ELSEIF z1 = 6 AND z2 = 6 THEN

SOUND 2000, 0.25

SET COLOR "green"

PRINT "Box Cars!", 12

SET COLOR "black"

ELSEIF z1 + z2 = 7 or z1+z2 = 11 THEN

SOUND 1500, 0.25

SET COLOR "blue"

PRINT "Craps!",z1+z2

SET COLOR "black"

ELSE

PRINT z1; z2

PAUSE 0.25

END IF

LET count = count+1

LOOP until count > 100

END

Prints out pairs of numbers simulating dice rolls, with comments.