Shuffle Array
Randomly shuffle an array.
'assumes MyArray already exists and is filled with data
'if you know the upper/lower limits of the array, just use them
'set temp variable to same type as MyArray
Dim i As Long , j As Long , temp As Variant
Randomize
For i = Lbound (MyArray) To Ubound (MyArray)
'randomly pick an element of the array to swap with element i
j = Int(( Ubound (MyArray)) * Rnd + 1)
temp = MyArray(i)
MyArray(i) = MyArray(j)
MyArray(j) = temp
Next i
Special Instructions
This content is reprinted for archival purposes from Gary Beene's Information Center, with permission from Mr. Beene himself.
Loading Comments ...
Comments
No comments have been added for this post.
You must be logged in to make a comment.