﻿ RANDOMIZE Statement ---------------------------------------------------------------------------- Action Initializes (reseeds) the random-number generator. Syntax RANDOMIZE expression% Remarks If you omit expression%, BASIC pauses and asks for a value by printing the following messages before executing the RANDOMIZE statement. Random Number Seed (-32768 to 32767)? When you use the argument expression%, BASIC uses this value to initialize the random-number generator. If the random-number generator is not reseeded, the RND function returns the same sequence of random numbers each time the program is run. To change the sequence of random numbers every time the program is run, place a RANDOMIZE statement at the beginning of the program and change the argument with each run. A convenient way to initialize the random-number generator is to use the TIMER function. Using TIMER ensures a new series of random numbers each time you use the program. See the example below. See Also RND, TIMER Example The following example uses RANDOMIZE to seed and reseed the random number generator. It uses 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 Output You rolled a 3 and a 5 for a total of 8 Roll again (Y-N)? n