Lee Evans Posted October 13, 2004 Share Posted October 13, 2004 I don't know if this is the best way to do something but what I want to do is select at random from a list and return this selection. I then want to select at random again but not choose any items I have already selected. My thoughts on doing this was to select from the list and then pass the selection to an array. I would then select again and ensure that the next selection did not exist in the array etc until all of the values were present in the array. Is this possible? Also how can I display the contents of an array? Has anyone any better ideas? Link to comment Share on other sites More sharing options...
trids Posted October 13, 2004 Share Posted October 13, 2004 [..]Also how can I display the contents of an array?[..]<{POST_SNAPBACK}>What version of AutoIt are you running? Cos there's a new StringJoin() function that may already be available in a phase of version 3.0.103, in which case you could just say something like...;Assuming the array is $aList MsgBox(0, "array contents", StringJoin($aList, @LF) ) Link to comment Share on other sites More sharing options...
Matt @ MPCS Posted October 13, 2004 Share Posted October 13, 2004 What version of AutoIt are you running? Cos there's a new StringJoin() function that may already be available in a phase of version 3.0.103, in which case you could just say something like...;Assuming the array is $aList MsgBox(0, "array contents", StringJoin($aList, @LF) )<{POST_SNAPBACK}>I just got the recent unstable release and I don't believe StringJoin is here yet, at least it isn't in the documentation. I don't think that would do what he wants anyway. If the intention of StringJoin is anything like the Join statement in VB then it just builds a string out of the array. This might help him with displaying an array but does nothing for... select at random from a list and return this selection.I then want to select at random again but not choose any items I have already selected. ...To keep the original contents of the array in tact while implementing what Larry suggested I would do something like this:$arrTemp = $arrList While UBound($arrTemp) >= 0 $rand = Int(Random( 0, UBound($arrTemp) )) MsgBox( 0, "Item " & $rand, "Element " & $rand & " contains " & $arrTemp[$rand] ) RemoveArrayElement( $arrTemp, $rand ) Wend Func RemoveArrayElement( $Array, $Element ) For $i = $Element To ( UBound($Array) - 2 ) $Array[$i] = $Array[$i + 1] Next ReDim $Array[$i - 1] Return $Array EndFuncThis should do what you need, but like I said it isn't tested. *** Matt @ MPCS 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