Jump to content

Recommended Posts

Posted

what is a random number?

it is a number that you do not know which one will be.

So, if you ask to a random() function to return a number, you expect a random number

if you try to fool the function by asking a number that can not properly be random, the function rightly refuse to provide that number so as not to be a liar (and fooled). otherwise the function would not be true to herself!

That's a very naive attempt to a formal definition which has no precise mathematical meaning at all. "...you do not know ..." doesn't translate to anything in mathematics, algorithmics or computer science in general. There is no "you" being an oracle.

A pseudo-random choice of one element from a set  S  of  k  elements {e1, e2, ..., ek} is the selection of any element  ei  of  S  in such a way that every element of  S  has probability exactly  1/k  of being chosen. In particular and like most languages / libraries implement this when the set considered in a closed interval  [a, b]  of  ℕ  or  ℤ , the case a = b is perfectly valid and provides the result  a  without any discussion.

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)

Posted

Apparently there is still some audience with blind eyes...

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)

Posted (edited)

 

On 9/28/2013 at 6:51 AM, PincoPanco said:

what is a random number?
it is a number that you do not know which one will be.
So, if you ask to a random() function to return a number, you expect a random number
if you try to fool the function by asking a number that can not properly be random, the function rightly refuse to provide that number so as not to be a liar (and fooled). otherwise the function would not be true to herself!

Actually, what you describe would be more akin to random(n) - and I think most people wouldn't be too confused about that failing (except AutoIt's Random assumes it to be the Max value and etc.)

I think the discussion ends up being of of philosophy - e.g. whether you view it as random number generation, or random number selection.

In the case of generation, you're basically taking the two inputs, n and m, converting them to numbers, 10 and 10, and then saying "now pick a random number between 10 and 10".  Since 10 is 10 is 10, there's no random selection to be made, and saying the generation failed can be seen as appropriate.

Edit: Thinking of it a bit more, an alternate view would be a physical number line. If you were to draw a line for the range (3,5) and ask a person to cross that line somewhere at random, that should be very easy to do, and the number closest to where it crosses would be the result for random(3,5) (assuming the underlying float to int would be a rounding function).  If you were to draw a 'line' for the range (10,10), you end up with a point.  While of course the dot of a pencil (a circle and thus along the number line a very short line) is something you could cross, hitting the point exactly is effectively impossible.

 

But if you think of it as random number selection, things change.  Let's take random(n=1,m=5) and assume it only selects integers.  You're basically asking it to pick from this sequence of numbers: n=1, 2, 3, 4, m=5.

The result is either n, m, or any of the integers in between.

Now take random(1,2).  You're asking it to pick from this sequence of numbers: n=1, m=2.

The result is either n or m.  There's no integers in between.

Now take random(10,10).  You're asking it to pick from this sequence of numbers: n=10, m=10.

The result is still either n or m.

Now, the result to you may always be '10' which makes you think it's not random.  But in terms of the random function, the '10' being returned may be n, or it may be m.  Essentially, the two 10s are not in fact the same thing, they just have the same value.

Or, alternatively by analogy, let's say you've got a coin with two heads.

Those of the former philosophy will simply claim that the coin cannot be flipped and anybody trying to do so should realize the pointlessness of trying.

Those of the latter accept that it's pointless to flip it, will happily flip it anyway, and accept that the result is heads.

( Somebody else in one of the other threads made the analogy of a deck of cards with all cards being, say, Ace of Spades, being handled by a magician and the magician showing them to you with the backs towards you, asking you to pick one at random.  Essentially, the fact that it's always going to be an Ace of Spades is unknown to you - but you still made the selection at random. )

Ultimately, I don't really care.. now that I know AutoIt's Random() has this 'gotcha', I know how to avoid it (by using _Random()) - but it's a trap easily fallen into, especially when coming from other languages.. documentation (at least it's in the beta) or not.

 

Edited September 28, 2013 by kamiquasi

New edit: Hey look at that, they changed the behavior in 3.3.14.0 (2015/Jul/10)
http://www.autoitscript.com/trac/autoit/ticket/2686

Thanks devs for listening!

Edited by kamiquasi

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...