ben7winnipeg Posted March 7, 2009 Share Posted March 7, 2009 Hi, I have been using autoit for a couple years as a software distribution tech and mostly using runwait and such to run msi's and such, but I have been wanting to expand my knowledge. I live in winnipeg canada and we have a lotto here called 6/49 you need 6 numbers of 49. I wrote a script that randomizes numbers 1-49 and if it is already in the array it will go back to randomizing... ********code********* #include <Array.au3> $LowerLimit = 1 $UpperLimit = 49 Dim $ArrayVar Dim $avArray[1] call("lotto") Func Lotto() $i = 0 Do $RandomNumber = Random($LowerLimit,$UpperLimit,1) $Pos = _ArraySearch ($avArray, $RandomNumber, 0, 0, 0, True) If $Pos = -1 Then _ArrayAdd( $avArray, $RandomNumber) EndIf $i = $i + 1 Until UBound($avArray, 1) = 44 EndFunc _ArrayDisplay( $avArray, "Whole array" ) **********code************* The script runs really good except if i want it to randomize the whole 49 numbers. if I ask for it to calculate 43 of 49 numbers i get an array in about 3 secs, if i ask for 44 I have never seen it finish. I have a dual xeon with 6GB of ram so it is not processing power. if anyone can explain this to me i would really apreciate it Link to comment Share on other sites More sharing options...
Developers Jos Posted March 7, 2009 Developers Share Posted March 7, 2009 (edited) Why did you put in the partial search = true in the ArraySearch? Try this version which works fine for me: $Pos = _ArraySearch($avArray, $RandomNumber) Edited March 7, 2009 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 7, 2009 Moderators Share Posted March 7, 2009 ben7winnipeg,This runs for me at between 1 and 20 ms and checks for duplicates. It uses a second array to check for duplicates:expandcollapse popup#include <Array.au3> $begin= TimerInit() $LowerLimit = 1 $UpperLimit = 49 $Required = 49 ; Set this to the value you require Global $CheckVar[50], $ArrayVar[$Required + 1] Call("lotto") ConsoleWrite(TimerDiff($begin) & @CRLF) For $i = 1 To $Required - 1 For $j = $i + 1 To $Required If $ArrayVar[$i] = $ArrayVar[$j] Then ConsoleWrite("Duplicate" & @CRLF) Next Next _ArrayDisplay($ArrayVar, "Whole array") Func Lotto() $i = 1 While 1 $RandomNumber = Random($LowerLimit, $UpperLimit, 1) If $CheckVar[$RandomNumber] = "" Then $ArrayVar[$i] = $RandomNumber $CheckVar[$RandomNumber] = 1 $i += 1 If $i > $Required Then ExitLoop EndIf WEnd EndFunc ;==>LottoThe code writes the generation time in SciTE. Obviously this depends on how many times Random produces an already used random number.Hope this is of use.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
ben7winnipeg Posted March 7, 2009 Author Share Posted March 7, 2009 Wow Melba, You are FRICKEN AWSOME! it ran so quick i couldnt tell you in the milli seconds. i really apreciate the response. I have a lot of interest in autoit, I used to dabble in Vb but just ran into too many roadblocks with my company. i love the compiled exe's! hiding serial numbers and package locations from the numb nut user has made all the difference especially using the piece o shite LAndesk... 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