AlmarM Posted March 12, 2010 Share Posted March 12, 2010 Hiya! I know I saw it somewhere on this forum, a 'random-no-repeat' function. I did some search, but I couldnt find anything. Mayby its me . So does anyone have a link or mayby a short code for me? I tried something, but wasn't even close. Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
99ojo Posted March 12, 2010 Share Posted March 12, 2010 Hi, maybe this one? http://www.autoitscript.com/forum/index.php?showtopic=106567&st=0&p=752356&hl=random&fromsearch=1&#entry752356 ;-)) Stefan Link to comment Share on other sites More sharing options...
AlmarM Posted March 12, 2010 Author Share Posted March 12, 2010 (edited) I would like something like: Global $RepeatString For $i = 1 To 10 ConsoleWrite(RandomNoRepeat(1, 10) & @CRLF) Next Func RandomNoRepeat($iMin, $iMax) $Random = Random($iMin, $iMax, 1) $Split = StringSplit($RepeatString, ";") For $i = 1 To $Split[0] If Not StringInStr($RepeatString, $Random) Then $RepeatString &= $Random & ";" Return $Random Else RandomNoRepeat($iMin, $iMax) EndIf Next EndFunc Not it's giving me an Overflow Stack error and some 0's. EDIT: If you add a _ArrayDisplay() it will succes, but will go on forever. :/ #include <Array.au3> Global $RepeatString For $i = 1 To 10 ConsoleWrite(RandomNoRepeat(1, 10) & @CRLF) Next Func RandomNoRepeat($iMin, $iMax) $Random = Random($iMin, $iMax, 1) $Split = StringSplit($RepeatString, ";") _ArrayDisplay($Split) For $i = 1 To $Split[0] If Not StringInStr($RepeatString, $Random) Then $RepeatString &= $Random & ";" Return $Random Else RandomNoRepeat($iMin, $iMax) EndIf Next EndFunc Edited March 12, 2010 by AlmarM Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
Xenobiologist Posted March 12, 2010 Share Posted March 12, 2010 No repeat means, unique or just the letter or numbers should not be like 55 but 123565312 would be okay? Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
AlmarM Posted March 12, 2010 Author Share Posted March 12, 2010 No repeat means, unique or just the letter or numbers should not be like 55 but 123565312 would be okay?Hmm, what do you exactly mean with that? Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
Xenobiologist Posted March 12, 2010 Share Posted March 12, 2010 I try to understand the goal of your function. RandomNoRepeat Does it mean you want to have a string where no equal sign follows the other? like 12432425435352435 Or do you want to have a string which is random, but contains only unique signs like 1254387690 Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
AlmarM Posted March 12, 2010 Author Share Posted March 12, 2010 I try to understand the goal of your function.RandomNoRepeat Does it mean you want to have a string where no equal sign follows the other? like 12432425435352435Or do you want to have a string which is random, but contains only unique signs like 1254387690Ah ok. Well, to be honest, I have no idea how I should create a RandomNoRepeat function.It actualy turned out well. Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
Xenobiologist Posted March 12, 2010 Share Posted March 12, 2010 Ah ok. Well, to be honest, I have no idea how I should create a RandomNoRepeat function.It actualy turned out well.So your already done with the task?Or do you want me to write the function? If so, then I need to clearify whether you want version a or version b as I mentioned above. Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
AlmarM Posted March 12, 2010 Author Share Posted March 12, 2010 (edited) So your already done with the task?Or do you want me to write the function? If so, then I need to clearify whether you want version a or version b as I mentioned above.Well, im not realy done, my function crashes and returns 0's.If you could make one, that would be perfect .Some information then:The functions has 2 params, Min and Max. (Used for the Random())Whenever the Random() is been calculated, it checks if it already exists. If so, calculate a new one.*If the calculated number isnt found, return it.*I guess this is were I fail, it keeps executing my function because the number was found. Edited March 12, 2010 by AlmarM Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
Xenobiologist Posted March 12, 2010 Share Posted March 12, 2010 Well, im not realy done, my function crashes and returns 0's.If you could make one, that would be perfect .Some information then:The functions has 2 params, Min and Max. (Used for the Random())Whenever the Random() is been calculated, it checks if it already exists. If so, calculate a new one.*If the calculated number isnt found, return it.*I guess this is were I fail, it keeps executing my function because the number was found.You need a 3rd parameter for the length of the string of numbers which should be returned, don 't you? Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
AlmarM Posted March 12, 2010 Author Share Posted March 12, 2010 You need a 3rd parameter for the length of the string of numbers which should be returned, don 't you?Would be awesome, I know it will be 4 or 5 as default. Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
Xenobiologist Posted March 12, 2010 Share Posted March 12, 2010 (edited) ;~ ConsoleWrite(_randomNr(100) & @CRLF) Func _randomNr($length = 1) Local $nr = Random(0, 9, 1), $tmp = '' While StringLen($nr) < $length $tmp = Random(0, 9, 1) If $tmp <> StringRight($nr, 1) Then $nr &= $tmp WEnd Return $nr EndFunc ;==>_randomNr ConsoleWrite(RandomNoRepeat(10, 0, 9) & @CRLF) Func RandomNoRepeat($length, $iMin, $iMax) If $length > $iMax - $iMin Then Return -1 Local $nr = Random($iMin, $iMax, 1), $tmp = '' While StringLen($nr) < $length $tmp = Random($iMin, $iMax, 1) If Not StringInStr($nr, $tmp) Then $nr &= $tmp WEnd Return $nr EndFunc ;==>RandomNoRepeat Edited March 12, 2010 by Xenobiologist Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
AlmarM Posted March 12, 2010 Author Share Posted March 12, 2010 ;~ ConsoleWrite(_randomNr(100) & @CRLF) Func _randomNr($length = 1) Local $nr = Random(0, 9, 1), $tmp = '' While StringLen($nr) < $length $tmp = Random(0, 9, 1) If $tmp <> StringRight($nr, 1) Then $nr &= $tmp WEnd Return $nr EndFunc ;==>_randomNr ConsoleWrite(RandomNoRepeat(10, 0, 9) & @CRLF) Func RandomNoRepeat($length, $iMin, $iMax) If $length > $iMax - $iMin Then Return -1 Local $nr = Random($iMin, $iMax, 1), $tmp = '' While StringLen($nr) < $length $tmp = Random($iMin, $iMax, 1) If Not StringInStr($nr, $tmp) Then $nr &= $tmp WEnd Return $nr EndFunc ;==>RandomNoRepeat Almost what I need. Let me explain what for. Im currently creating a LAN Chat + Hangman and I need a 'unique' session ID for each player that connects. Im currently using a Random(1000, 9999, 1) as session ID. It's ok. But I felt like, I needed more security, dont want dubble session ID's. Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
Xenobiologist Posted March 12, 2010 Share Posted March 12, 2010 Hi, you could use something like this: #include <Crypt.au3> $nr = _randomNr(20) _Crypt_Startup() MsgBox(0, "MD5", $nr & @CRLF & _Crypt_HashData($nr, $CALG_MD5)) _Crypt_Shutdown() Func _randomNr($length = 1) Local $nr = Random(0, 9, 1), $tmp = '' While StringLen($nr) < $length $tmp = Random(0, 9, 1) If $tmp <> StringRight($nr, 1) Then $nr &= $tmp WEnd Return $nr EndFunc ;==>_randomNr Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times 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