argumentum Posted March 4, 2016 Posted March 4, 2016 ..so I'm testing code for a project where many clients are governed by a master. To test, I generate a random result to emulate real life BUT all the randoms are at unison. Here is an example of what I see: expandcollapse popupIf @Compiled Then Exit MsgBox(0, "Master - RandomTest", "please run this from the editor", 10) #NoTrayIcon #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $iManyTesters = 10 ; how many I run but they all give the same random number ! Global $iRandom = 0 Global $SEC = @SEC If $CmdLine[0] Then AutoItWinSetTitle("RandomTester # " & $CmdLine[1]) While 1 If $SEC <> @SEC Then $SEC = @SEC $iRandom = Random(0, 4, 0) ControlSetText("Master - RandomTest", "", "Edit" & $CmdLine[1], StringRight("00" & $CmdLine[1], 2) & ") " & $iRandom) EndIf Sleep(10) WEnd Exit EndIf Global $n, $Form = GUICreate("Master - RandomTest", 300, 50 + (24 * $iManyTesters) - 46) For $n = 1 To $iManyTesters GUICtrlCreateInput("Input" & $n, 2, 2 + (24 * $n) - 24, 296, 24, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) GUICtrlSetFont(-1, 15, 400, 0, "Terminal") Next GUISetState(@SW_SHOW) Global $aTesters[$iManyTesters + 1] $aTesters[0] = $iManyTesters $SEC = @SEC Do Sleep(10) Until $SEC <> @SEC For $n = 1 To $iManyTesters $aTesters[$n] = Run('"' & @AutoItExe & '" "' & @ScriptFullPath & '" ' & $n) Next While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete() For $n = 1 To $iManyTesters ProcessClose($aTesters[$n]) Next Exit EndSwitch WEnd is there a better way to generate a random number. One that if generated at the same instance in time, the number would be more random ? Thanks in advance for any pointers to my question. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
argumentum Posted March 4, 2016 Author Posted March 4, 2016 (edited) Solution: read the help file ! expandcollapse popupIf @Compiled Then Exit MsgBox(0, "Master - RandomTest", "please run this from the editor", 10) #NoTrayIcon #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $iManyTesters = 10 ; how many I run but they all give the same random number ! Global $iRandom = 0 Global $SEC = @SEC If $CmdLine[0] Then AutoItWinSetTitle("RandomTester # " & $CmdLine[1]) SRandom(@AutoItPID) ; <--- solution: read the help file ! While 1 If $SEC <> @SEC Then $SEC = @SEC $iRandom = Random(0, 4, 0) ControlSetText("Master - RandomTest", "", "Edit" & $CmdLine[1], StringRight("00" & $CmdLine[1], 2) & ") " & $iRandom) EndIf Sleep(10) WEnd Exit EndIf Global $n, $Form = GUICreate("Master - RandomTest", 300, 50 + (24 * $iManyTesters) - 46) For $n = 1 To $iManyTesters GUICtrlCreateInput("Input" & $n, 2, 2 + (24 * $n) - 24, 296, 24, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) GUICtrlSetFont(-1, 15, 400, 0, "Terminal") Next GUISetState(@SW_SHOW) Global $aTesters[$iManyTesters + 1] $aTesters[0] = $iManyTesters $SEC = @SEC Do Sleep(10) Until $SEC <> @SEC For $n = 1 To $iManyTesters $aTesters[$n] = Run('"' & @AutoItExe & '" "' & @ScriptFullPath & '" ' & $n) Next While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete() For $n = 1 To $iManyTesters ProcessClose($aTesters[$n]) Next Exit EndSwitch WEnd Edited March 4, 2016 by argumentum found the solution LarsJ 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
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