Sign in to follow this  
Followers 0
igotandrew

Array Shuffling

3 posts in this topic

I'm just not in the thinking mood today, or something.

I searched it, it came in a function for 2d arrays, I tried to get it down to one.

Func ArrShuffle(ByRef $myArray)
    Local $temp[1] = [0], $X = 1
    Local $numElements = Ubound($myArray) - 1
    ;Loop through all array elements
    For $X = 1 to $numElements
        ;Store copy of current element
        $temp[0] = $myArray[$X]
        ;MsgBox(0, 0, "$temp[0] = " & $myArray[$X])
        
        $random = Random($X, $numElements, 1)
        ;MsgBox(0, 0, "Random number = " & $Random)
        ;Overwrite current element with random element
        $myArray[$X] = $myArray[$random]
        ;MsgBox(0, 0, "$myArray[$X] = " & $myArray[$x] & " - swapped data w/ " & $random)

        ;Overwrite random element with original copy of current element
        $myArray[$random] = $temp[0]
    Next
EndFunc   ;==>ArrShuffle

sometimes, it'll also shuffle the 0 entry, which in most of my cases is the number of entries.

So I end up with array problems, when trying to fix it.

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0