|
Post by yorkshirelad on Oct 17, 2008 17:18:13 GMT -5
I've been tinkering around with an array, and I need to randomize it. I can sort the array using a sort routine, however I need to randomize the output each time the program is run.
Has anyone any code that may help solve this please?
|
|
|
Post by Janet on Oct 17, 2008 21:43:33 GMT -5
When you say randomizing, do you mean shuffling?
nElements = 10 ' Fill the array sequentially Dim MyArray(nElements) For i = 1 to nElements MyArray(i) = i Next i
For i = 1 to nElements Print i;": ";MyArray(i) Next i ' Randomize the array For i = nElements to 2 Step -1 switch = Int(Rnd(1) * i) + 1 temp = MyArray(i) MyArray(i) = MyArray(switch) MyArray(switch) = temp Next i
Print: Print
' Display the array For i = 1 to nElements Print i;": ";MyArray(i) Next i
|
|