Jump to content
Sign in to follow this  
Warpi

Why Random(10, 10, 1) returns 0 and set @error?

Recommended Posts

Warpi

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 integers

When using integers Max-Min must be less than 2^31

Am I misreading something?.

Regards.

Share this post


Link to post
Share on other sites
JohnOne

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.

Share this post


Link to post
Share on other sites
guinness

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
Warpi

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.

Share this post


Link to post
Share on other sites
jchd

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.

  • Like 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 here
RegExp tutorial: enough to get started
PCRE 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)

Share this post


Link to post
Share on other sites
Warpi

[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.

Share this post


Link to post
Share on other sites
jchd

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 here
RegExp tutorial: enough to get started
PCRE 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)

Share this post


Link to post
Share on other sites
guinness

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 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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
Warpi

LOL. Ok jchd, after reading the ticket, it's time to give up :bye:

Lets handle the mathematics weakness of the developers with external error bug-handling code :oops:

Share this post


Link to post
Share on other sites
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.

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 by Warpi

Share this post


Link to post
Share on other sites
czardas

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 code

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.

Share this post


Link to post
Share on other sites
trancexx

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

Share this post


Link to post
Share on other sites
czardas

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. :oops:

Share this post


Link to post
Share on other sites
trancexx

:oops: You said sex something.

So, you like sex. Big deal.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
czardas

hehe, I sense a hint of a Freudian slip somewhere in there, however I was trying to account for the possibilty of quintuplets. :oops:

Edited by czardas

Share this post


Link to post
Share on other sites
jchd

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 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 here
RegExp tutorial: enough to get started
PCRE 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)

Share this post


Link to post
Share on other sites
Rogue5099

Even with getting the numbers from an outside source you should put a check in for human error!

If $x >= $n then

FAIL

Else

Random($x, $n, 1)

Endif

Edit:

Also Add IsInt for those technical people!!!

Edited by rogue5099

Share this post


Link to post
Share on other sites
czardas

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 by czardas

Share this post


Link to post
Share on other sites
jchd

@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 here
RegExp tutorial: enough to get started
PCRE 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)

Share this post


Link to post
Share on other sites
jchd

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 here
RegExp tutorial: enough to get started
PCRE 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)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×