Lee Evans 0 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? Share this post Link to post Share on other sites
trids 2 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) ) Share this post Link to post Share on other sites
Matt @ MPCS 0 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 Share this post Link to post Share on other sites