MariusN Posted November 11, 2009 Posted November 11, 2009 Can a script contain 2 loops that can run simultaniously? The 1 must generate random numbers, while the other stops the loop, gets a number, and continues...If YES (i hope), could you maby give me an example? I have compiled a lotto program that works 100%, but to get 6 numbers, you have to actually CLICK the button SIX times to get random numbers...otherwise all numbers are the same...lol
Moderators Melba23 Posted November 11, 2009 Moderators Posted November 11, 2009 MariusN, Look at this - it avoids duplicates as well : #include <Array.au3> Global $aNumbers[6] For $i = 0 To 5 Do $iNumber = Random(1, 49, 1) Until _ArraySearch($aNumbers, $iNumber) = -1 $aNumbers[$i] = $iNumber Next _ArrayDisplay($aNumbers) 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
whim Posted November 11, 2009 Posted November 11, 2009 AutoIt is not multi-threaded, so it can not run 2 loops at the same time. However, i'm pretty sure it will be possible to tweak your programs' logic to get arounnd that, there's actually surprisingly few cases (IMHO) where multi threading is absolutely necessary - and i doubt if generating 6 random numbers is one of those whim
Mison Posted November 12, 2009 Posted November 12, 2009 Aren't they random? Example 1: $random_num = "" For $i = 1 To 6 $random_num &= Round(Random(0,9)) Next MsgBox(0,"",$random_num) Example 2: $random_num = "" For $i = 1 To 6 $random_num &= Round(Random(1000,4000))&@CRLF Next MsgBox(0,"",$random_num) Hi ;)
AdmiralAlkex Posted November 12, 2009 Posted November 12, 2009 Aren't they random?Hw wanted RANDOM and UNIQUE, your code doesn't do that. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface
Mison Posted November 12, 2009 Posted November 12, 2009 Well, if that was the case, then Melba23's code will be just the solution. Hi ;)
MariusN Posted November 12, 2009 Author Posted November 12, 2009 MariusN, Look at this - it avoids duplicates as well : #include <Array.au3> Global $aNumbers[6] For $i = 0 To 5 Do $iNumber = Random(1, 49, 1) Until _ArraySearch($aNumbers, $iNumber) = -1 $aNumbers[$i] = $iNumber Next _ArrayDisplay($aNumbers) M23 Thank you M23...this is exactly what i wanted. Is there a way of "pausing" so to speak this function?What i mean is lets say i want the program to display only ONE no out of the 6 ( the amount of no's ill have at the end).for at least 250 ms intervals? The "LOOP" must basicly carry on looping, and A no (only 1 at a time till all 6 are there) have to be retrieved from it every 250ms. Is this possible? If this is a stupid question, please ignore...
Moderators Melba23 Posted November 12, 2009 Moderators Posted November 12, 2009 MariusN, Because I am feeling generous today: expandcollapse popup#include <GUIConstantsEx.au3> #include <Array.au3> Global $iMax_Numbers = 6, $iLowest_Num = 0, $iHighest_Num = 50 ; Adjust these to change the number and the range of random numbers produced $hGUI = GUICreate("Random Numbers", 180, 260) $hLabel = GUICtrlCreateLabel("How many numbers (1-" & $iMax_Numbers & ")?", 10, 10, 200, 20) $hInput = GUICtrlCreateInput("", 10, 30, 50, 20) $hUD = GUICtrlCreateUpdown($hInput) GUICtrlSetLimit(1, 6) $hButton = GUICtrlCreateButton("Go!", 10, 70, 80, 30) $hNumber = GUICtrlCreateLabel("", 10, 120, 200, 200) GUICtrlSetFont(-1, 96, 800) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hButton Roll() EndSwitch If GUICtrlRead($hInput) < 1 then GUICtrlSetData($hInput, 1) If GUICtrlRead($hInput) > $iMax_Numbers then GUICtrlSetData($hInput, $iMax_Numbers) WEnd Func Roll() Local $aNumbers[$iMax_Numbers] Local $iCount = GUICtrlRead($hInput) For $i = 0 To $iCount - 1 Do $iNumber = Random($iLowest_Num, $iHighest_Num, 1) Until _ArraySearch($aNumbers, $iNumber) = -1 $aNumbers[$i] = $iNumber GUICtrlSetData($hNumber, $iNumber) Sleep(1000) ; Adjust this to keep the number on screen longer Next GUICtrlSetData($hNumber, "") EndFunc 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
MariusN Posted November 17, 2009 Author Posted November 17, 2009 MariusN, Because I am feeling generous today: expandcollapse popup#include <GUIConstantsEx.au3> #include <Array.au3> Global $iMax_Numbers = 6, $iLowest_Num = 0, $iHighest_Num = 50 ; Adjust these to change the number and the range of random numbers produced $hGUI = GUICreate("Random Numbers", 180, 260) $hLabel = GUICtrlCreateLabel("How many numbers (1-" & $iMax_Numbers & ")?", 10, 10, 200, 20) $hInput = GUICtrlCreateInput("", 10, 30, 50, 20) $hUD = GUICtrlCreateUpdown($hInput) GUICtrlSetLimit(1, 6) $hButton = GUICtrlCreateButton("Go!", 10, 70, 80, 30) $hNumber = GUICtrlCreateLabel("", 10, 120, 200, 200) GUICtrlSetFont(-1, 96, 800) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hButton Roll() EndSwitch If GUICtrlRead($hInput) < 1 then GUICtrlSetData($hInput, 1) If GUICtrlRead($hInput) > $iMax_Numbers then GUICtrlSetData($hInput, $iMax_Numbers) WEnd Func Roll() Local $aNumbers[$iMax_Numbers] Local $iCount = GUICtrlRead($hInput) For $i = 0 To $iCount - 1 Do $iNumber = Random($iLowest_Num, $iHighest_Num, 1) Until _ArraySearch($aNumbers, $iNumber) = -1 $aNumbers[$i] = $iNumber GUICtrlSetData($hNumber, $iNumber) Sleep(1000) ; Adjust this to keep the number on screen longer Next GUICtrlSetData($hNumber, "") EndFunc M23 Thanks M23
jvanegmond Posted November 17, 2009 Posted November 17, 2009 A programmer once had a problem. He thought: "I know! I'll use multi threading." The programmer now has two problems. github.com/jvanegmond
MariusN Posted November 17, 2009 Author Posted November 17, 2009 A programmer once had a problem. He thought: "I know! I'll use multi threading."The programmer now has two problems.lol...
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