Warpi Posted March 16, 2012 Posted March 16, 2012 Hi,If I execute Random($n, $n, 1) then it set the @error flag and returns 0.According to the help file I cannot find what is wrong with that, imho in this case Random() should just return $n.The help file reads: The result will be in the range of Min to Max INCLUSIVE when using integersWhen using integers Max-Min must be less than 2^31Am I misreading something?.Regards.
JohnOne Posted March 17, 2012 Posted March 17, 2012 Because min and max are equal and are seemingly interpreted as bad parameters. it's trivial to test for equal values yourself, so the expense should be in your script and not the autoit interpreter. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
guinness Posted March 17, 2012 Posted March 17, 2012 There are no integers between 10 and 10 so why would you use Random? This doesn't fail though >> ConsoleWrite(Random(10, 11) & @LF) UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
Warpi Posted March 17, 2012 Author Posted March 17, 2012 There are no integers between 10 and 10 so why would you use Random?Yes, strictly between 10 and 10 is pretty obvious that there are no integers and need no further explanation.This doesn't fail though >>Yes it does as long as it follows the help guide text:The result will be in the range of Min to Max INCLUSIVE when using integers"INCLUSIVE" is in caps, so it emphasizes that includes both limits, i.e, between 10 and 10 there is just one random integer: 10.Obviously again, in this case there is no need to randomize, but the Min and Max values are not hardcoded on the script but variables that come from an external device and can be the same value.Yes, the script should test that, no problem on this, is easy and fast, however the help text is not strictly true and because of this I spent more than a couple of hours looking for the bug. I am not complaining on the latter but suggesting if the help text should be modified.Regards.
jchd Posted March 17, 2012 Posted March 17, 2012 I confess I always question why Random($n, $n, 1) fails to return $n. Mostly since, YES, there exists one (unique) integer between 10 and 10. Mathematically speaking, [10, 10] = {10} As Warpi says, it's trivial to test for equality of bounds and code accordingly, but fixing Random to behave logically would be preferable in my view to making the help file clearer on this point, and that won't break any script. Warpi 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
Warpi Posted March 17, 2012 Author Posted March 17, 2012 [10, 10] = {10} I couldn't have said it better. As Warpi says, it's trivial to test for equality of bounds and code accordingly, but fixing Random to behave logically would be preferable in my view to making the help file clearer on this point, and that won't break any script. Totally agree.
jchd Posted March 17, 2012 Posted March 17, 2012 This has been the basis for several tickets already, like #1538 and previous ones. Don't spend time asking again (IMHO). This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
guinness Posted March 17, 2012 Posted March 17, 2012 (edited) warpi, My small example was between 10 & 11 not 10 & 10. Anyway a comment has already been added to the Help file, see the latest betas. Edited March 17, 2012 by guinness UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
Warpi Posted March 17, 2012 Author Posted March 17, 2012 LOL. Ok jchd, after reading the ticket, it's time to give up Lets handle the mathematics weakness of the developers with external error bug-handling code
Warpi Posted March 17, 2012 Author Posted March 17, 2012 (edited) My small example was between 10 & 11 not 10 & 10. Anyway a comment has already been added to the Help file, see the latest betas.Oh, yes, I was talking not about your example but about having the same two limits. As I wrote, in my script those come from an external source and can have the same value.I will check the latest beta help file then.Well, it is nice it says "If Min and Max are the same value then Random will return 0 and set @error to non-zero.".Thank you. Edited March 17, 2012 by Warpi
czardas Posted March 18, 2012 Posted March 18, 2012 There are no integers between 10 and 10 so why would you use Random?I agree that it sounds like a crazy thing to do, however I see it like this: as the min value approaches the max value, so too does the random value between them. I would call it an asymptotic relationship.Lets handle the mathematics weakness of the developers with external error bug-handling codeThere is absolutely no justification for this comment. Firstly it's total nonesence, and secondly their decision may be based on any number of criteria which we may not be aware of. I trust the devs judgement and I think AutoIt is brilliant. operator64 ArrayWorkshop
trancexx Posted March 18, 2012 Posted March 18, 2012 There is absolutely no justification for this comment. Firstly it's total nonesence, and secondly their decision may be based on any number of criteria which we may not be aware of. I trust the devs judgement and I think AutoIt is brilliant.Hm, I disagree.Everything can be questioned. I would say that developer who made decision to return 0 and set @error was wrong.No amount of sugar can change the bitter taste of wrongness. ♡♡♡ . eMyvnE
czardas Posted March 18, 2012 Posted March 18, 2012 Hm, I disagree.Everything can be questioned. I would say that developer who made decision to return 0 and set @error was wrong.No amount of sugar can change the bitter taste of wrongness.The fact is Trancexx, I didn't bother to look at the ticket, so I had no idea who Warpi was refering to. When he refered to the mathematical weakness of the developers, the word developers was in the plural. I took it to mean the dev team in general. I certainly would not consider your mathematics to be weak. I also would prefer Random($n, $n) to return $n, but then I would also like to replace binary with sexagesimal. operator64 ArrayWorkshop
trancexx Posted March 18, 2012 Posted March 18, 2012 You said sex something. So, you like sex. Big deal. ♡♡♡ . eMyvnE
czardas Posted March 18, 2012 Posted March 18, 2012 (edited) hehe, I sense a hint of a Freudian slip somewhere in there, however I was trying to account for the possibilty of quintuplets. Edited March 18, 2012 by czardas operator64 ArrayWorkshop
jchd Posted March 18, 2012 Posted March 18, 2012 (edited) czardas, It isn't about replacing anything by something else (sexy or not), but rather bringing back Random to the realm of pure logic: the interval [x, x] contains exactly one element which is x whatever set you're working in. That means in particular: ∀ x ∊ ℤ, x ≤ x ≥ x trancexx, Would it be a great fuss doing so? The only scripts it would break are those which rely on Random($n, $p, 1) to set @error and return 0 as a way for detecting that $n = $p. That seems very unlikely to me and it's certainly not a problematic breaking. Edited March 18, 2012 by jchd This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
Rogue5099 Posted March 18, 2012 Posted March 18, 2012 (edited) Even with getting the numbers from an outside source you should put a check in for human error!If $x >= $n thenFAILElseRandom($x, $n, 1)EndifEdit:Also Add IsInt for those technical people!!! Edited March 18, 2012 by rogue5099 My projects: Inventory / Mp3 Inventory, Computer Stats
czardas Posted March 18, 2012 Posted March 18, 2012 (edited) czardas, It isn't about replacing anything by something else (sexy or not), but rather bringing back Random to the realm of pure logic: the interval [x, x] contains exactly one element which is x whatever set you're working in. Replacing binary was just a joke, since I have been thinking about rhythmic divisions recently (triplets, quintuplets), and trying to decide what approach to take. Base 60 being intuitive, although I haven't yet come to a decision. That means in particular: ∀ x ∊ ℤ, x ≤ x ≥ x Okay I get an idea what this statement is saying, but I'm not familiar with all the symbols. Edited March 18, 2012 by czardas operator64 ArrayWorkshop
jchd Posted March 18, 2012 Posted March 18, 2012 @rogue5099 The qhole point of the thread was to stress (once again) that Random($n, $n, 1) returning an error was completely wrong. You proposed code does exactly the same. I'd even say that given the fact that Random is a slow operation, it would have been nice to restore bounds order internally. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
jchd Posted March 18, 2012 Posted March 18, 2012 For any x in the set of signed integers, (x is smaller or equal to x) and (x is greater or equal to x). Comes from the fact that x = x = x This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
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