Difference between revisions of "221: Random Number"

Explain xkcd: It's 'cause you're dumb.
Jump to: navigation, search
(general trivia not trivia)
Line 17: Line 17:
                   // guaranteed to be random.
                   // guaranteed to be random.
The comic also has a philosophical bent, by showcasing the limits of knowledge for an external observer. Someone who is calling this function, but unable to see its source code, will never be able to tell with 100% confidence whether the function is flawed. Even if he runs the function 10 times, and it always returns 4, there is always the possibility that it could be a fluke. As he runs the function more and more times, he can develop more confidence in the theory that the function is faulty. But unless he breaks the barrier and examines the source code itself, she will never be able to declare the function to be faulty with 100% confidence.
Despite the extreme example given, this is actually a practical problem which likely exists in the real world. If the function was more sophisticated but still had a 5% bias towards one number under certain circumstances, this would be extremely hard to notice & prove. More likely, the API users would continue to believe that the RNG is working as intended, without realizing the flaw inherent in it; anyone who grumbles about seeing 4 very frequently may even be accused of not understanding the non-uniform nature of randomness. Given the extremely large number of APIs & libraries present, and that not all of them are fully examined & understood by 3rd party experts, such flaws are likely present in our world as well. These flaws may even have been purposely introduced by a malicious agent or entity seeking to exploit them.
{{comic discussion}}
{{comic discussion}}

Revision as of 06:55, 4 September 2014

Random Number
RFC 1149.5 specifies 4 as the standard IEEE-vetted random number.
Title text: RFC 1149.5 specifies 4 as the standard IEEE-vetted random number.


The comic specifies a function (in a C-like syntax), which should return a random number. Most functions of this form are random number generators, implying that they return on subsequent calls different numbers. But the programmer has instead created a function that just returns always the same random number; random, because it was chosen by rolling a die as the comment documented. This function is essentially worthless, as it could simply be replaced by a "4" wherever it is used. And in fact, most modern compilers would do this automatically.

The IEEE is the organization responsible for maintaining a number of computer standards. An RFC, or Request for Comments, is a formal document put out to computing experts by IETF in the hopes of becoming a future standard. However, RFC 1149 was an April Fools' joke, defining how carrier pigeons can be used to transmit Internet packets. The RFC 1149.5 simply does not exist.


int getRandomNumber()
    return 4;     // chosen by fair dice roll.
                  // guaranteed to be random.

comment.png add a comment! ⋅ comment.png add a topic (use sparingly)! ⋅ Icons-mini-action refresh blue.gif refresh comments!


The syntax looks like perfectly valid java to me. 22:00, 11 March 2013 (UTC)

Looks like Java to me too. (talk) (please sign your comments with ~~~~)

Java code for this would be something like "public static int fin(){}" or just "public int fin(){}". I think the code would still compile though without the public/private part. (talk) (please sign your comments with ~~~~)
I know this comment is from several years ago, but I'll add this just for posterity. The "default" access modifier exists in java and is somewhere in between "private" and "protected". You can only use it by otherwise unspecifying the access modifier. 16:40, 18 July 2016 (UTC)
How can Java come to mind when it is pure C syntax, which predates Java by several years and is arguably better known. A feature of most languages is that they have a "C-like syntax". See, a whole page on Wikipedia - http://en.wikipedia.org/wiki/List_of_C-based_programming_languages 19:53, 22 August 2013 (UTC)
"C-like syntax" is the best explain, this covers all. Even when I disagree that it's better known than Java these days.--Dgbrt (talk) 21:04, 22 August 2013 (UTC)
Just to be particularly pedantic, the double slash for the comment (which is generally utilised in object oriented C-style languages) should be avoided in C to retain backwards compatibility with C89, although it's a valid construct in C99. I'd offer, too, that the lack of library inclusion suggests this isn't necessarily Java, though it's been a couple years since I've had the opportunity to code in it. Thokling (talk) 15:35, 20 September 2013 (UTC)
Not really worth putting effort in backward compatibility for stuff a simple regex can fix:
$ perl -pi.bak -e 's!//(.*)$!/\*$1\*/!' *.c 03:23, 5 August 2015 (UTC)

As a proof of good joke, RFC 1149 was successfully implemented several times. -- Hkmaly (talk) 08:55, 11 May 2013 (UTC)

Actually, a poor “random” function like “return 4;” would be quickly determined by statistical test tools (Diehard, Dieharder, etc.) to generate very poor random number. Samiam (talk) 19:55, 28 October 2013 (UTC)

The number is random, I'm sure Randall really did this "fair dice roll". And even the name of the function is correct, it just returns a random number. A programmer would expect a random number generator, but Randall can't roll the dice all the time.--Dgbrt (talk) 21:37, 28 October 2013 (UTC)
<<sound of crickets chirping>> 02:24, 6 February 2014 (UTC)
Playstation 3 jailbreak reference?

Isn't this a reference to Sony Playstation 3's random number generator function that allowed to discover the private key to 3.55 firmware? (talk) (please sign your comments with ~~~~)

The comic is from February 9, 2007. The 3.55 firmware was released December 7, 2010. (talk) (please sign your comments with ~~~~)

This seems to have turned up in SMBC. .42 (talk) 20:00, 18 July 2016 (UTC)

Possibly turned up in Gravity Falls. Journal 3 (book edition) states that the Infinity-Sided Die can theoretically result in any outcome, but "you'd be surprised how often you'd roll a 4." 04:18, 19 October 2018 (UTC)