Good morning all --
I need to create a five element array with five random numbers between 1 and 9. The only catch is that there can be no duplicates. I'm getting infinite loops on this, and am hoping that someone can take a look and give my code a tweak in the right direction.
The desired end result: 5 elements with 5 unique random numbers between 1 and 9.
Thanks for any input!
Paul Prewett
I need to create a five element array with five random numbers between 1 and 9. The only catch is that there can be no duplicates. I'm getting infinite loops on this, and am hoping that someone can take a look and give my code a tweak in the right direction.
The desired end result: 5 elements with 5 unique random numbers between 1 and 9.
Code:
dim randArray(5), i, j, upperLimit, lowerLimit, good, number
upperLimit = 9
lowerLimit = 1
for i = 1 to 5
good = false
do while not good
randomize
number = Int((upperLimit - lowerLimit) * Rnd() + lowerLimit)
do while j <= 5
if randArray(j) = number then
good = false
exit do
else
good = true
end if
j = j + 1
loop
loop
randArray(i) = number
next
Thanks for any input!
Paul Prewett