Jump to content
Sign in to follow this  

_ArrayShuffle UDF

Recommended Posts

Try it out.

; Function Name:    _ArrayShuffle()
; Description:    Shuffles the elements in an array.
; Parameter(s):  $av_array - The array to shuffle. 
;                $i_base  - The first element of the array.
;                  ...
; Requirement(s):   None.
; Return Value(s):  none.
; Author(s):        Quick_sliver007.
; Note(s):        None.
Func _ArrayShuffle(ByRef $av_array, $i_base = 0)
    Local $max_index = UBound($av_array) -1
    Local $rand
    Local $temp
    Local $x
    For $x = $i_base To $max_index
        $rand = Random($i_base,$max_index)
        $temp = $av_array[$x]
        $av_array[$x] = $av_array[$rand]
        $av_array[$rand] = $temp
Dim $array[10]
For $i = 0 to 9
    $array[$i] =$i
_ArrayDisplay($array,"Before shuffle")
_ArrayDisplay($array,"After shuffle")

I hope you like it.


Share this post

Link to post
Share on other sites

interesting use of arrays

- Matt :whistle:

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post

Link to post
Share on other sites

I use the RAND func and _ArrayDelete as I go along so I don't repeat.

For $i = $iArrayTotal To 1 Step - 1
    $iRand = Random(1, $i, 1)

    // do stuff here to array element

    _ArrayDelete($aSource, $iRand)

Not sure which would be more efficient (most likely yours is) ;) but then again I wrote mine like 6 months ago.

I like your implementation better tho...

Edited by sshrum

Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'


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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...