Sign in to follow this  
Followers 0
quick_sliver007

_ArrayShuffle UDF

6 posts in this topic

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
    Next
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;
#include<array.Au3>
Dim $array[10]
For $i = 0 to 9
    $array[$i] =$i
Next
_ArrayDisplay($array,"Before shuffle")
_ArrayShuffle($array)
_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

#3 ·  Posted (edited)

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)
Next

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

Damn...took me like 2 minutes to integrate your shuffle function code into my Shuffler project. ;)

Like I said before, I'm not sure which is faster but my gut instinct sez yours is...I'm too lazy to do time tests :P


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

quick_sliver007:

I love that laughing man picture ;)


Start -> Programs -> AutoIt v3 -> AutoIt Help File -> Index -> (The Function you are asking about)----- Links -----DllStruct UDFsRSA Crypto UDFs

Share this post


Link to post
Share on other sites

QS, nice code. Such a simple idea. Why did I not think of it. :P

Cheers.. ;)

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