Dana Posted February 4, 2011 Share Posted February 4, 2011 (edited) I'm finding some more weirdness in the Random function. Do (some stuff) $randidx[$i] = Random(1, $array[0], 1) ; pick a random integer between 1 and $array[0] (some more stuff) $i = $i + 1 Until $i = $desired + 1 If I run the script from SciTE, a get a different set of random numbers each time, as expected. However, if the script is compiled to an exe, I get the same set of numbers each time I run the exe. Is this a bug? What is the Random function using as a seed if SRandom isn't used? It doesn't seem to be too big a deal; adding: SRandom(_Date_Time_GetTickCount()) just before the Do loop solves it even in the exe, but I'd like to know what's going on... and why the compiled executable should behave differently from the uncompiled script? Edited February 4, 2011 by Dana Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 4, 2011 Moderators Share Posted February 4, 2011 Dana,Just tried and I get random random numbers each time I run this script both in SciTE and compiled: Global $aArray[10] For $i = 0 To 9 $aArray[$i] = Random(0, 1000, 1) Next MsgBox(0, "Result", $aArray[0] & @CRLF & _ $aArray[1] & @CRLF & _ $aArray[2] & @CRLF & _ $aArray[3] & @CRLF & _ $aArray[4] & @CRLF & _ $aArray[5] & @CRLF & _ $aArray[6] & @CRLF & _ $aArray[7] & @CRLF & _ $aArray[8] & @CRLF & _ $aArray[9])I also use the Random function in my desktop MP3 player and it certainly does not repeat the same tracks each time I run it. 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...
Dana Posted February 4, 2011 Author Share Posted February 4, 2011 I dunno why it should be different, but I consistent got the same set of "random" numbers each time I ran the exe version... that's why I was wondering what gets used as a seed if you don't use the SRandom function first. Hmmm... if I compile it (your example) with obfuscator, it breaks and I get the same series every time. If I don't use obfuscation, it works as it should. Link to comment Share on other sites More sharing options...
MvGulik Posted February 4, 2011 Share Posted February 4, 2011 (edited) Your post is empty Edited February 9, 2011 by iEvKI3gv9Wrkd41u "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 4, 2011 Moderators Share Posted February 4, 2011 Dana,Even when the script above is Obfuscated (/sf /sv /om /cs=0 /cn=0) I still get random random numbers. 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...
willichan Posted February 4, 2011 Share Posted February 4, 2011 $randidx[$i] = Random(1, $array[0], 1) ; pick a random integer between 1 and $array[0] Is $array[0] returning a value of 1 by any chance? If the Min and Max are the same number, Random returns a 0 and sets @error. See this discussion --> If that is your case, I posted a little function to "fix" it in that thread. My UDFs: Barcode Libraries, Automate creation of any type of project folder, File Locking with Cooperative Semaphores, Inline binary files, Continue script after reboot, WinWaitMulti, Name Aggregator, Enigma, CornedBeef Hash Link to comment Share on other sites More sharing options...
Dana Posted February 5, 2011 Author Share Posted February 5, 2011 No, $array[0] is in the neighborhood of 5,000 or so. Melba23, I'm using the default Obfuscator settings during compile. Strange... at work I get the repeated results I described with the above example. At home, it works properly. Guess I'll have to wait until Monday to see what the difference may be. Interestingly, I looked at the obfuscated au3 file and I see that obfuscator added the line: SRandom(Number(StringRight(TimerInit(),4))) even though SRandom isn't used in the original code. Link to comment Share on other sites More sharing options...
Dana Posted February 8, 2011 Author Share Posted February 8, 2011 Grrr... returning to the office this morning, both the obfuscated and unobfuscated compiled versions return a different random series each time, as it should. Which makes me question: The obfuscated version adds the line with the SRandom function which isn't in my original script. (why?) That line uses TimerInit as input to SRandom. I know TimerInit "Returns a timestamp (in milliseconds)" according to the helpfile, but a time based on what? If the computer has been on for a long time (a week or two, as it was before I shut it down last Friday) would it "max out" and return the same value each time? Link to comment Share on other sites More sharing options...
jvanegmond Posted February 8, 2011 Share Posted February 8, 2011 (edited) Ofcourse, if you have a truly random dice and you throw it an infinite number of times, the probably of it rolling on the same number a hundred times in a row are approaching 100%. Maybe you were the lucky one. In all the years I have used AutoIt I have never seen the timestamp "max out". That would also probably have been noticed, since it will lead to unexplained bugs in long-running scripts in a production environment and cause someone to do some serious debugging. Perhaps you were facing an issue like this one: While 1 $time = TimerInit() ; Do all kinds of things ; Do all kinds of things ; Do all kinds of things ; Do all kinds of things ; Do all kinds of things ; Do all kinds of things ; Do all kinds of things ; Do all kinds of things ; Do all kinds of things $time = 5 ; Do all kinds of things ; Do all kinds of things ; Do all kinds of things ; Do all kinds of things ; Do all kinds of things ; Do all kinds of things ; Do all kinds of things ; Do all kinds of things ; Do all kinds of things ; Oh how convenient, don't need to call timerinit again SRandom($time) ; Pure delicous rando~.. OH WWHAT!! *Makes thread* ConsoleWrite(Random(0, 10) & @CRLF) WEnd Edited February 8, 2011 by Manadar github.com/jvanegmond Link to comment Share on other sites More sharing options...
MvGulik Posted February 8, 2011 Share Posted February 8, 2011 (edited) Your post is empty Edited February 9, 2011 by iEvKI3gv9Wrkd41u "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
Developers Jos Posted February 8, 2011 Developers Share Posted February 8, 2011 whateverWhy a post edit with a well know phrase but hidden?Referring to anything happened recently? 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...
MvGulik Posted February 9, 2011 Share Posted February 9, 2011 (edited) Your post is empty Edited February 9, 2011 by iEvKI3gv9Wrkd41u "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
Yashied Posted February 9, 2011 Share Posted February 9, 2011 Redirecting off topic item. -> ← SRandom(@AutoItPID) My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
Developers Jos Posted February 9, 2011 Developers Share Posted February 9, 2011 Redirecting off topic item. -> ← Correct ..... 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...
MvGulik Posted February 10, 2011 Share Posted February 10, 2011 (edited) Your post is empty Edited February 12, 2011 by iEvKI3gv9Wrkd41u "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... 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