Randomize command for BASIC programming
Date: Around 1995
What is the command in BASIC programming to have the computer make a random
selection? I am doing a program and it is driving me bonkers!
Assign sequential integers to represent the possible selections. Call the
random number generation function (perhaps RAN, RANDOM or RND??) to get a
real number from 0.0 to 1.0 (If your lucky your random number generator will
return integers in a selected range. If so, you are done!) Now you just
need to devise a way to "map" the number returned from your random number
generator to your selections. If you have assigned numbers to your selec-
tions starting with 1 then multiply the random number by the number of
selections and add 1.0. Finally, truncate the resulting real number. The
integer part will (randomly) point to one of your selections.
Click here to return to the Computer Science Archives
Update: June 2012