K3vin Posted June 15, 2005 Share Posted June 15, 2005 (edited) Hello, Here is the idea. I got the idea to make a script that would randomly give me a number (or better, a name) between 1 and 32 (each number for a name). But this script wouldn't give for example the number 1 once it has already been given! For example : 1 = Pipeline. The script randomly gives "Pipeline". I launch the script a second time and it gives "Pipeline" again! No!! I don't want that :-) Once one number/name has been chosen, it can't be given one more time UNTIL the 31 other numbers/names have been given after. Question : -What commands should I look for? (I mean on the AutoIt HelpFile) I already looked for the command "Random" but it didn't help me a lot :-s Thanks! Edited June 15, 2005 by K3vin Link to comment Share on other sites More sharing options...
/dev/null Posted June 15, 2005 Share Posted June 15, 2005 Create a random number between 1 and 32. random(1,32,1). Then write your random number to the registry. Next time you start. Create a random number. Check if number is already in registry. If so, create a new numer, until you find the one that's not in the registry. Look for random(), RegRead() and RegWrite()CheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
blindwig Posted June 15, 2005 Share Posted June 15, 2005 Create a random number between 1 and 32. random(1,32,1). Then write your random number to the registry. Next time you start. Create a random number. Check if number is already in registry. If so, create a new numer, until you find the one that's not in the registry. Look for random(), RegRead() and RegWrite()CheersKurt<{POST_SNAPBACK}>This sounds like a good idea, but as the list gets longer your number-picking routine gets exponentially slower.A better way is this:Make an array of numbers, sequentially. Now scramble the array (like shuffling cards) and, like /dev/null said, write it to the registry.Now each time you need a number, pop one off that array. If there is none left, generate a new list and start over.This method insures that you go through all numbers before getting another one again. My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions Link to comment Share on other sites More sharing options...
Valuater Posted June 15, 2005 Share Posted June 15, 2005 (edited) if your intention is to show all 32 names/num before they can be shown again... and the name/num does not change "until" the script is launched again then why is there a need to randomize the output? 8) Edited June 15, 2005 by Valuater Link to comment Share on other sites More sharing options...
/dev/null Posted June 15, 2005 Share Posted June 15, 2005 This sounds like a good idea, but as the list gets longer your number-picking routine gets exponentially slower.yes, you're right. However, I think with 32 numbers it won't take too long. Anyway, a better solution would be:1. read all previous numbers from registry2. create an array $missing, which contains numbers not yet created3. create random number from 1..$missing[0]4. pick $missing[$random]5. write $random to registryCheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
blindwig Posted June 15, 2005 Share Posted June 15, 2005 yes, you're right. However, I think with 32 numbers it won't take too long. Anyway, a better solution would be:1. read all previous numbers from registry2. create an array $missing, which contains numbers not yet created3. create random number from 1..$missing[0]4. pick $missing[$random]5. write $random to registryCheersKurt<{POST_SNAPBACK}>IMO that seems needlessly complicated. Try this out:CODEFunc _ArrayShuffle(ByRef $Array) Dim $i, $j, $k If IsArray($Array) Then For $i = 1 to $Array[0] $j = Random(1,$Array[0]) $k = $Array[$i] $Array[$i] = $Array[$j] $Array[$j] = $k Next EndIfEndFuncFunc _RandomUnique($Highest) Dim $Return $Highest = Int($Highest) Dim $aNums = StringSplit(regread('HKLM\Software\AutoIt v3\AutoIt\Custom','Random' & $Highest),',') $Return = _ArrayPop($aNums) If $aNums[0] <= 1 Then ;need to create a new list Dim $aNums[$Highest + 1] $aNums[0] = $Highest For $i = 1 to $Highest $aNums[$i] = $i Next _ArrayShuffle($aNums) If $Return = '' Then $Return = _ArrayPop($aNums) $aNums[0] = UBound($aNums) - 1 EndIf RegWrite('HKLM\Software\AutoIt v3\AutoIt\Custom','Random' & $Highest, 'REG_SZ', _ArrayToString($aNums, ',', 1)) Return $Return EndFuncThe function _RandomUnique(x) will return a number 1..x (inclusive) that will not repeat a number until all other numbers have been picked. My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions Link to comment Share on other sites More sharing options...
Valuater Posted June 15, 2005 Share Posted June 15, 2005 Well, i was working on this.... for a file works the first time but... arrays arent my thing (yet) expandcollapse popup#include <GUIConstants.au3> #include <File.au3> #include <Array.au3> #include <String.au3> ; I always include alot of stuff - then i dont have the problem later Dim $DLine; [32] ; place this file anywhere you want If Not FileExists(@HomeDrive & "\Temp\list.txt") Then $list = "bill,george,john,mat,deb,frank,missy,hank,fred,shawana,bob,terry,etc" FileWrite(@HomeDrive & "\Temp\list.txt", $list) EndIf $NFile = FileOpen(@HomeDrive & "\Temp\list.txt", 0) ; Check if file opened for reading OK If $NFile = -1 Then MsgBox(0, "Error", "Unable to open file.") EndIf ; Read in line(s) of text until the EOF is reached While 1 $NLine = FileReadLine($NFile) If @error = -1 Then ExitLoop If $NLine <> "" Then $DLine = StringSplit( $NLine,",") EndIf WEnd FileClose($NFile) FileDelete(@HomeDrive & "\Temp\list.txt") _ArrayDisplay( $DLine, "UnSorted" );>>>>>>>>> for testing _ArraySort( $DLine) $Name_to_use = _ArrayPop ($DLine); removes the last entry ??? _ArrayDisplay( $DLine, "Sorted" );>>>>>>>>> for testing $list=$Dline If $DLine[0] >= 2 then FileWrite(@HomeDrive & "\Temp\list.txt", $List ) MsgBox(0,"Test","Name to use is " & $Name_to_use) i think outside the box(registry) maybe one of these guys who really know thier stuff can see the direction here and fix it 8) Link to comment Share on other sites More sharing options...
/dev/null Posted June 15, 2005 Share Posted June 15, 2005 (edited) IMO that seems needlessly complicated. Try this out:Complicated? I don't think so...#include <Array.au3> func _getUniqueRandom($min,$max) dim $numbers[$max+1] local $nUnused, $regval for $i = $min to $max $regval = RegRead('HKLM\Software\AutoIt\Randoms',"Random" & $i) if $regval <> 1 then $nUnused = $nUnused + 1 $numbers[$nUnused] = $i endif next if $nUnused = 0 then return -1 $random = Random(1,$nUnused,1) RegWrite('HKLM\Software\AutoIt\Randoms',"Random" & $numbers[$random],"REG_DWORD",1) return $numbers[$random] endfunc msgbox(0,"","Random: " & _getUniqueRandom(1,32))CheersKurt Edited June 15, 2005 by /dev/null __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
K3vin Posted June 15, 2005 Author Share Posted June 15, 2005 Wow, thanks people ! Now, I'm gonna try to understand what these commands are used for. If I have any question, I'll write it here :-) Thanks people: ) 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