IKilledBambi Posted June 30, 2008 Share Posted June 30, 2008 This is almost what I want but, I want it to keep randomizing, after it randomizes one, it doesnt re-randomize. $1 = Random( 1, 999, 1 ) While 1 Sleep( 100 ) Send($1) WEnd Link to comment Share on other sites More sharing options...
monoceres Posted June 30, 2008 Share Posted June 30, 2008 Just move the random part to the line above the sleep part. Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
IKilledBambi Posted June 30, 2008 Author Share Posted June 30, 2008 Cool thanks man, is there a way so that, if the number is 234 the program will close? Link to comment Share on other sites More sharing options...
monoceres Posted June 30, 2008 Share Posted June 30, 2008 If $1=234 Then Exit Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
IKilledBambi Posted June 30, 2008 Author Share Posted June 30, 2008 ok then after that, how do i make it execute a function? I tried execute but it was fail xD While 1 $1 = Random( 1, 999, 1 ) Sleep( 100 ) Send( "{space}" ) Send($1) if $1=666 then MsgBox(1, "AHHH DEVIL", "DEVIL AHHHHHHHHHHHHH" ) Execute( devilish ) EndIf WEnd Func devilish() While 1 Sleep( 100 ) WEnd EndFunc Link to comment Share on other sites More sharing options...
monoceres Posted June 30, 2008 Share Posted June 30, 2008 You do not call functions with the Execute function, you do it simply like this: devilish() Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
IKilledBambi Posted June 30, 2008 Author Share Posted June 30, 2008 Is there a way to recycle old numbers meaning, if 99 was said, it wont be said again? Link to comment Share on other sites More sharing options...
system24 Posted June 30, 2008 Share Posted June 30, 2008 test this: While 1 $last = $1 $1 = Random(1, 999, 1) While $1 = $last $1 = Random(1, 999, 1) WEnd ;rest of script goes here WEnd [center]It's a question of mind over matter, if I don't mind, it doesn't matter.[/center] Link to comment Share on other sites More sharing options...
IKilledBambi Posted June 30, 2008 Author Share Posted June 30, 2008 no go Link to comment Share on other sites More sharing options...
monoceres Posted June 30, 2008 Share Posted June 30, 2008 (edited) Something like: $MIN=1 $MAX=40 $string="|" While 1 Sleep(10) Do $temp=Random($MIN,$MAX,1) Until Not StringInStr($string,"|"&$temp&"|") Send($temp) $string&=$temp&"|" $array=StringRegExp($string,"\|",3) If Ubound($array)>=($MAX-$MIN+2) Then ExitLoop WEnd Could also be done with arrays... Edited June 30, 2008 by monoceres Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
Kiti Posted June 30, 2008 Share Posted June 30, 2008 Hi, monoceres! What if I have many text strings, and I want to randomly pick up one of them, and do not reapeat any previous one, but after they are all finished, start over, randomizing strings, and so on ? Regards, Kiti Think outside the box.My Cool Lego Technic Website -- see walking bipeds and much more!My YouTube account -- see cool physics experimentsMy scripts:Minesweeper bot: Solves advanced level in 1 second (no registry edit), very improved GUI, 4 solving stylesCan't go to the toilet because of your kids closing your unsaved important work? - Make a specific window uncloseableCock Shooter Bot -- 30 headshots out of 30 Link to comment Share on other sites More sharing options...
SkinnyWhiteGuy Posted June 30, 2008 Share Posted June 30, 2008 I thought of this the other day, it's basically a shuffle algorithm, like what you would use to place every card in a deck in a random position, without repeating the cards. Easiest solution I could think of, was to make 2 arrays, both the size of the data. Fill 1 with your data to be shuffled. Then, select one at random (using AutoIt's Random(1, 52, 1) for a standard card deck), add that card to the other array at position 1. After the card is selected, remove it from the first array, and update a variable pointing at the current position in the 2nd array. Next run, the Random function would run, but for one less (Random(1, 51, 1)), and so on, until you only had one card, and then you'd have it shuffled. Only problem with that solution, would be the deleting elements from an array, that causes things to slow down a lot. For those willing to try, you could actually use just 1 array, and when you pick a card to be moved, just exchange it with either ending variable (just swap values), and change your Random function to match (either update the 1 to 2 if you add things at the beginning, or 52 to 51 if you add things to the end). That gives you a nice speed boost, reduces the memory your program will eat, and is just a cool solution to the problem in general. Have fun getting it to work. Link to comment Share on other sites More sharing options...
monoceres Posted June 30, 2008 Share Posted June 30, 2008 Like this (doing an array solution this time) Dim $strings[5]=["hi","hello","hej","hallo","ola"] $strings=_RandomizeArray($strings) Local $count=0 While 1 Sleep(100) Send($strings[$count]) $count+=1 If $count=Ubound($strings)-1 Then $strings=_RandomizeArray($strings) $count=0 EndIf WEnd Func _RandomizeArray($array) Local $out[Ubound($array)] For $element In $array Do $i=Random(0,Ubound($out)-1,1) Until $out[$i]="" $out[$i]=$element Next Return $out EndFunc This also works for numbers of course. Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
SkinnyWhiteGuy Posted June 30, 2008 Share Posted June 30, 2008 Well, monoceres, that will work, but it can take a lot of time, if your Random keeps picking locations that already have data in them, which can happen if you get down to the last few elements in the input array. Also, if the value in the input array was "", and is picked again, your going to overwrite it (but, that would just leave some other location at "", so that's not too bad). That's the main reason I did mine with a changing random function, to avoid times where it might run fast, and then the next time take a lot longer to finish. Link to comment Share on other sites More sharing options...
monoceres Posted June 30, 2008 Share Posted June 30, 2008 I believe this is faster: ; More levels = better shuffling but slower execution time. Func _RandomizeArray(ByRef $array, $level=3) Local $size=Ubound($array) For $crap=1 To $level For $i=0 To $size-1 $rand=Random(0,$size-1,1) $temp=$array[$i] $array[$i]=$array[$rand] $array[$rand]=$temp Next Next EndFunc But the shuffling could be quite bad considering an element could be moved back and forth to the same position it original had. Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
SkinnyWhiteGuy Posted June 30, 2008 Share Posted June 30, 2008 Couldn't that also happen in real life? I could shuffle a deck 100 times, and a card in it could end up right back in it's original starting location. Link to comment Share on other sites More sharing options...
monoceres Posted June 30, 2008 Share Posted June 30, 2008 (edited) Couldn't that also happen in real life? I could shuffle a deck 100 times, and a card in it could end up right back in it's original starting location.Yeah, but I wouldn't consider shuffling card in real life as real random, but for card shuffling algorithms, fine.I used the swap algorithm for my solitaire game in my sig for example (The Idiot). Edited June 30, 2008 by monoceres Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
SkinnyWhiteGuy Posted June 30, 2008 Share Posted June 30, 2008 If you don't consider shuffling in real life as real random, what do you consider real random? Would rolling dice to put the cards in order be more random? Same thing could happen there. Not trying to argue with you, but the general perception of randomness most people have is horribly wrong. Link to comment Share on other sites More sharing options...
monoceres Posted June 30, 2008 Share Posted June 30, 2008 If you don't consider shuffling in real life as real random, what do you consider real random? Would rolling dice to put the cards in order be more random? Same thing could happen there.Not trying to argue with you, but the general perception of randomness most people have is horribly wrong.Something that is not affected by humans for starters. Humans are terrible at generating random stuff (just look at my grandma when she's shuffling the cards, no random there).A well known random generator is a geiger counter. I guess I consider it a very good random generator.I don't think there are any true random because everything happens because something else affected it, therefore if every possible parameter is known in a case, then it can be foreseen and thus not making it true random. Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
monoceres Posted June 30, 2008 Share Posted June 30, 2008 Here's the version that uses the faster algorithm, it works... Dim $strings[5]=["hi","hello","hej","hallo","ola"] _RandomizeArray($strings) Local $count=0 While 1 Sleep(100) Send($strings[$count]) $count+=1 If $count=Ubound($strings)+1 Then _RandomizeArray($strings) $count=0 exit EndIf WEnd ; More levels = better shuffling but slower execution time. Func _RandomizeArray(ByRef $array, $level=3) Local $size=Ubound($array) For $crap=1 To $level For $i=0 To $size-1 $rand=Random(0,$size-1,1) $temp=$array[$i] $array[$i]=$array[$rand] $array[$rand]=$temp Next Next EndFunc Broken link? PM me and I'll send you the file! 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