czardas Posted October 5, 2014 Share Posted October 5, 2014 (edited) This is an interesting problem and here's a simple solution. You have a sequence of events you want to change at random. You decide to loop through a shuffled array but, on subsequent runs, random is throwing out the same data twice in a row and breaking the intended sequence. The following function prevents this from happening; unless the array contains duplicate data, in which case the whole concept is flawed. ; Func ArrayNonConsecutive(ByRef $avArray) If Not IsArray($avArray) Or UBound($avArray, 0) > 1 Then Return SetError (1) ; Wrong input Local $iBound = UBound($avArray) -1 If $iBound < 1 Then Return SetError (2) ; Not enough elements in the array Local $vFirst = $avArray[0], $vLast = $avArray[$iBound] For $i = 0 To $iBound InternalSwap($avArray, $i, Random (0, $iBound, 1)) Next ; Prevent consecutive repeat sequences on subsequent calls to the function by swapping the first with the last element. If $avArray[0] = $vLast Or $avArray[$iBound] = $vFirst Then InternalSwap($avArray, 0, $iBound) EndFunc ;==> ArrayNonConsecutive Func InternalSwap(ByRef $avArray, $iElement1, $iElement2) Local $vTemp = $avArray[$iElement1] $avArray[$iElement1] = $avArray[$iElement2] $avArray[$iElement2] = $vTemp EndFunc ;==> InternalSwap ; =============================================================== ; Testing that elements do not repeat. Local $a1234[4] = [1,2,3,4], $sTest = "" For $i = 1 To 25 ; Produce 100 non-repeating characters (25 *4) ArrayNonConsecutive($a1234) For $j = 0 To 3 $sTest &= $a1234[$j] Next Next ConsoleWrite($sTest & @LF) ; =============================================================== ; The difference with the method here, and those suggested previously, is that it guarantees that all elements can be accessed (using a loop) in some sequence or other; and that no element can appear twice in a row during subsequent runs. Selecting elements at random does not guarantee that all elements will be accessed. As long as you are consistent, it doesn't matter which direction you loop through the modified arrays: the result is always the same. The input array should contain at least three elements. I couldn't think of a suitable name for this function. If someone comes up with one, then please feel free to suggest it. Edits: Refinements to code. Edited October 5, 2014 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
kylomas Posted October 5, 2014 Share Posted October 5, 2014 czardas, Selecting elements at random does not guarantee that all elements will be accessed. Good point, not sure if that is part of the OP's criteria but should be considered. Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
czardas Posted October 5, 2014 Share Posted October 5, 2014 Perhaps it's not what the OP wants. Looping through the items in a random sequence with the condition that no repeats occur on subsequent runs is very specific. I thought it was worth posting anyway because it's somewhat related. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
JohnOne Posted October 5, 2014 Share Posted October 5, 2014 Hey, look at you with your blue badge there. You sell out. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
czardas Posted October 5, 2014 Share Posted October 5, 2014 Funny thing happened John, I appear to have become an Everton fan. JohnOne 1 operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Bert Posted October 6, 2014 Share Posted October 6, 2014 I hate to ask this, but can somebody tell me where this can be honestly used in anything other than a game? I honestly think this is being used to get past something like PunkBuster or GameGuard. I've been in computers since 1995, worked with thousands of applications and I've never heard of a need of such a thing other than to get past an app like PunkBuster or GameGuard. I want to educate myself here so if there is a legit need, I would be happy to learn something new. Thanks. The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
JohnOne Posted October 6, 2014 Share Posted October 6, 2014 Automated testing of applications or websites. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Bert Posted October 6, 2014 Share Posted October 6, 2014 Automated testing of applications or websites. I thought of that, but why the need to randomize? When you test an application and you have just 4 buttons, it isn't hard to work out all possible combinations. Either it works or it doesn't. If it is a website, again, either it works or it doesn't. In my current and last job I do testing and I work with many people who do testing. The need to randomize the clicks still makes no sense. If it is the real reason for the OP's request, I'm cool with it but I still think this is for a game until the OP states what he is using it for. The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
JohnOne Posted October 6, 2014 Share Posted October 6, 2014 Users of apps and the internet are generally stupid and press random things. Pressing random things on them as a way of testing is very very valid and can often lead to exposing obscure bugs. Pissing around on paint is another use, or any other art app among many many other reasons. What can possibly be gained from clicking random places in a game? Serious question I don't really play games, but I thought you had to click in very specific areas. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Bert Posted October 6, 2014 Share Posted October 6, 2014 PunkBuster will look to see if you click in the same manner over and over. If you do it is a sure sign of automation. The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
DarksSaber Posted October 7, 2014 Author Share Posted October 7, 2014 DarksSaber, My mistake, you should update to the latest release of Autoit. I'm on this for the editor: SciTE Version 3.4.4 Jul 13 2014 20:07:38 I hate to ask this, but can somebody tell me where this can be honestly used in anything other than a game? I honestly think this is being used to get past something like PunkBuster or GameGuard. I've been in computers since 1995, worked with thousands of applications and I've never heard of a need of such a thing other than to get past an app like PunkBuster or GameGuard. I want to educate myself here so if there is a legit need, I would be happy to learn something new. Thanks. I thought of that, but why the need to randomize? When you test an application and you have just 4 buttons, it isn't hard to work out all possible combinations. Either it works or it doesn't. If it is a website, again, either it works or it doesn't. In my current and last job I do testing and I work with many people who do testing. The need to randomize the clicks still makes no sense. If it is the real reason for the OP's request, I'm cool with it but I still think this is for a game until the OP states what he is using it for. Eh was more of an exercise to figure out how to use Arrays and ShuffleArray with other things. I couldn't figure out why Shuffle wouldn't work for a bit since I guess I don't have the most recent libraries. If you're worried if this is for a bot for a game, I am not using this to create a bot to automate gameplay. Link to comment Share on other sites More sharing options...
Bert Posted October 7, 2014 Share Posted October 7, 2014 Thank you The Vollatran project My blog: http://www.vollysinterestingshit.com/ 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