Editing 221: Random Number

Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 7: Line 7:
 
}}
 
}}
 
==Explanation==
 
==Explanation==
The comic specifies a function (in a {{w|C (programming language)|C}} similar syntax), which judging by its name should be designed to return a random number. Most functions of this form are random number ''generators'', meaning that on subsequent calls they return ''different'' random numbers. But the programmer has instead implemented a function that just returns the ''same'' random number each time, which, while it could indeed have been truly randomly chosen by rolling a die as the [[156: Commented|comment]] documented, is essentially worthless were it ever to be called more than once (with the expectation of different, i.e., random, results). In other words, the results over time would not be random at all, but completely predictable and deterministic.
+
The comic specifies a function (in a {{w|C (programming language)|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.
  
Alternatively, this could be seen as making fun of how people normally will erroneously think of "random numbers".  A mathematician will (or at least should) think about a random number as one that is independent of something (usually being independent of the next number in a list of numbers).  However a normal person will often think of a list of random numbers as just meaning it having "no pattern".  This difference is described in [https://simple.wikipedia.org/wiki/Hacker_koan#Uncarved_block an MIT koan]. (Just to drive this point home, if the first number of a list is "4", and the second number is independent of the first, then that means the second number can also be "4" (as well as the 3rd and 4th).  This obviously creates a "pattern", while still being random because of the independence)
+
The {{w|IEEE}} is the organization responsible for maintaining a number of computer standards. An RFC, or {{w|Request for Comments}}, is a formal document put out to computing experts by {{w|IETF}} in the hopes of becoming a future standard. However, RFC 1149 was an {{w|April Fools' Day Request for Comments|April Fools' joke}}, defining how carrier pigeons have to be used to transmit Internet packets. Ironically, although the RFC was written in 1990, a homing pigeon with a couple microSD cards tied to its leg might well be faster than your typical consumer Internet connection in the US today. The <nowiki>RFC 1149.5</nowiki> simply does not exist.
 
 
The {{w|IEEE}} is the organization responsible for maintaining a number of computer standards. An RFC, or {{w|Request for Comments}}, is a formal document put out to computing experts by {{w|IETF}} in the hopes of becoming a future standard. However, RFC 1149 was an {{w|April Fools' Day Request for Comments|April Fools' joke}}, defining how carrier pigeons can be used to transmit Internet packets. "<nowiki>RFC 1149.5</nowiki>," meanwhile, simply does not exist.
 
 
 
==Trivia==
 
 
 
* The well-known "helper website" ([http://gChq.github.io/CyberChef/#recipe=XKCD_Random_Number() CyberChef]) has a function that simulates XKCD's program.
 
* Esolangs.org features a [http://esolangs.org/wiki/user:XKCD_Random_Number challenge] that requires you to rewrite the program in XKCD's comic in another programming language, as either a function or a full program that prints the "4".
 
  
 
==Transcript==
 
==Transcript==
[A computer program.]
 
 
  int getRandomNumber()
 
  int getRandomNumber()
 
  {
 
  {
    return 4; // chosen by fair dice roll.
+
    return 4;     //chosen by fair dice roll.
              // guaranteed to be random.
+
                  //guaranteed to be random.
 
  }
 
  }
 +
 +
==Trivia==
 +
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 she runs the function 10 times, and it always returns 4, there is always the possibility that it could be a fluke. As she runs the function more and more times, she can develop more confidence in the theory that the function is faulty. But unless she 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}}
 
[[Category:Programming]]
 
[[Category:Programming]]
 
[[Category:Computers]]
 
[[Category:Computers]]
[[Category:Comics with lowercase text]]
 

Please note that all contributions to explain xkcd may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see explain xkcd:Copyrights for details). Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:

Cancel | Editing help (opens in new window)