bas7ex.hlp (Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
RANDOMIZE and RND Programming Example
                       ◄Example►                 ◄Contents►  ◄Index►  ◄Back►
──────────────────────────────────────────────────────────────────────────────
'This example uses the RANDOMIZE statement to seed and reseed the random
'number generator and the RND function to simulate rolling a pair of dice.
 
'Use the timer as the seed for the number generator.
RANDOMIZE TIMER
DO
   'Simulate rolling two dice using RND.
   D1 = INT(RND * 6) + 1
   D2 = INT(RND * 6) + 1
   'Report the roll.
   CLS    'Clear screen.
   PRINT "You rolled a"; D1; "and a"; D2; "for a total of"; D1 + D2
   INPUT "Roll again (Y/N)"; Resp$
   PRINT
LOOP UNTIL UCASE$(MID$(Resp$, 1, 1)) = "N"
END
 
'Sample Output
'
'You rolled a 3 and a 5 for a total of 8
'Roll again (Y/N)? y
'
'You rolled a 4 and a 1 for a total of 5
'Roll again (Y/N)? y
'
'You rolled a 5 and a 6 for a total of 11
'Roll again (Y/N)? n