Name: Taylor
Status: N/A
Age: N/A
Location: N/A
Country: N/A
Date: Around 1995
Question:
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!
Replies:
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.
NEWTON is an electronic community for Science, Math, and Computer Science K-12 Educators, sponsored and operated by Argonne National Laboratory's Educational Programs, Andrew Skipor, Ph.D., Head of Educational Programs.