qb45advr.hlp (Topic list)
RANDOMIZE Statement Programming Example
  QuickSCREEN      Details     Example      Contents      Index
──────────────────────────────────────────────────────────────────────────────
RANDOMIZE Statement Programming Example
 
This example uses RANDOMIZE 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