quick_sliver007 Posted September 4, 2005 Share Posted September 4, 2005 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. . Link to comment Share on other sites More sharing options...
theguy0000 Posted September 5, 2005 Share Posted September 5, 2005 interesting use of arrays - Matt The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN Link to comment Share on other sites More sharing options...
sshrum Posted September 8, 2005 Share Posted September 8, 2005 (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 September 8, 2005 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' Link to comment Share on other sites More sharing options...
sshrum Posted September 8, 2005 Share Posted September 8, 2005 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 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' Link to comment Share on other sites More sharing options...
Ejoc Posted September 8, 2005 Share Posted September 8, 2005 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 Link to comment Share on other sites More sharing options...
busysignal Posted September 10, 2005 Share Posted September 10, 2005 QS, nice code. Such a simple idea. Why did I not think of it. Cheers.. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now