smallbasic - Random Numbers in array, Small Basic -
i'm trying generate array have ten variables, each containing random number 1 10. random integer can not in array more once. each time program execute, array reset different numbers. example, in english, essentially:
randint[1] = random number <= 10 , >= 1 randint[2] = random number <= 10 , >= 1 , <> randint[1] randint[3] = random number <= 10 , >= 1 , <> randint[2] randint[4] = random number <= 10 , >= 1 , <> randint[3] randint[5] = random number <= 10 , >= 1 , <> randint[4] randint[6] = random number <= 10 , >= 1 , <> randint[5] randint[7] = random number <= 10 , >= 1 , <> randint[6] randint[8] = random number <= 10 , >= 1 , <> randint[7] randint[9] = random number <= 10 , >= 1 , <> randint[8] randint[10] = random number <= 10 , >= 1 , <> randint[9]
simply, trying sort numbers 1 10 in random order in array.
so far code follows:
for = 1 10 while rand_int[i] = prev_int rand_int[i] = math.getrandomnumber(9)+1 prev_int = rand_int[i] endwhile endfor
i have tried instead
rand_int[1] = math.getrandomnumber(9)+1 = 2 10 rand_int[i] = math.getrandomnumber(9)+1 while rand_int[i] = rand_int[i-1] rand_int[i] = math.getrandomnumber(9)+1 endwhile endfor
any assistance appreciated, thanks.
boom! got figured out. created array of numbers, counted 1 ten, , scrambled order of numbers:
for = 1 10 randint[i] = endfor = 1 30 'the larger number, more scrambles order rand1 = math.getrandomnumber(10) rand2 = math.getrandomnumber(10) oldrandint = randint[rand1] randint[rand1] = randint[rand2] 'here swapping 2 random varibles in array randint[rand2] = oldrandint endfor = 1 10 textwindow.writeline(randint[i]) endfor
Comments
Post a Comment