Thread: How exactly does the random number generator work?

  1. #1
    Registered User Finchie_88's Avatar
    Join Date
    Aug 2004
    Posts
    154

    How exactly does the random number generator work?

    I was wondering. How exactly are random numbers generated, and by that I don't mean the method of seeding the random number generator etc, I mean "under the hood" as it were (I dislike that phrase with a passion, but its the only phrase which came to mind). Also, exactly how random are these supposedly random numbers?


  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    13
    Well it works like any function I believe, although the rand() function may be more complex, a simple approach is, you can make a function called MyRand(47); and then you use a series of equations, and then you get some different number, but you have to use the initial number in the formula multiple times. The result will seem random, but it's not. So every time you type 47, you'll get maybe 535, but of course that wouldn't always work out. So how can it be random? Well you base the initial number on time, so its almost always random.

    MyRand(time()); time() being a function that grabs the current time. GetTickCount() in win32 would work too.

    However, remember rand() itself is probably a lot more complex resulting in more random numbers.

    The reason for all this? Random doesn't exist that's why. Everything in nature and the world, is based on cause and effect. Just like programming functions. Hence IMO the human brain itself can also be a big C++ program if someone had the time to create such a complex and time consuming program.

    If you don't believe me, well, think about how you define random? A dice roll? Well dice gives you a random number but it actually gives you the number that appears after the amount of force you used to throw the dice and the surface area and other conditions causes the dice to roll and tumble into a certain position, which can probably be calculated, but of course, its not random.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I suggest reading Prelude's Random Numbers and Using rand() articles. If you are interested in something less deterministic than pseudorandom number generation algorithms, then take a look at HotBits.

    If you don't believe me, well, think about how you define random? A dice roll?
    That would be a rather poor definition since it defines a property in terms of a specific example. One cannot conclude that the alleged property does not exist because it can be explained away in the specific example.
    Last edited by laserlight; 08-23-2007 at 11:21 PM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Aug 2007
    Posts
    13
    Quote Originally Posted by laserlight View Post
    That would be a rather poor definition since it defines a property in terms of a specific example. One cannot conclude that the alleged property does not exist because it can be explained away in the specific example.
    Science is observation not the absence of observation being the proof.
    Therefore, unless you can prove to me random exists, mathematically or whatever, then tell me :P. (And if it is I apologize, my Math is not that great).

    So a dice would be a way some describe a random number. Or perhaps the thing that picks the lottery numbers, which also isn't random, just depends on the physics of the air and balls pumped inside etc.

    I dont know how else you can describe a random number in nature.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Science is observation not the absence of observation being the proof.
    Therefore, unless you can prove to me random exists, mathematically or whatever, then tell me :P. (And if it is I apologize, my Math is not that great).
    One can define randomness as a statistical property, in which case it clearly exists because it has been observed in nature and in our pseudorandom number algorithms. One could also define it as some objective inherent unpredictability, in which case physics provides a possible example as exploited by HotBits.

    So a dice would be a way some describe a random number. Or perhaps the thing that picks the lottery numbers, which also isn't random, just depends on the physics of the air and balls pumped inside etc.

    I dont know how else you can describe a random number in nature.
    Describing the effect of a property and defining a property are two different things. I do not object to using dice as an example to describe randomness, and then pointing out that it is not really random, though humans often perceive it as such. In practice though, it is "random", since for its purpose the outcome of the roll of a fair die is unpredictable.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    > Science is observation not the absence of observation being the proof.

    Observation alone should be able to tell you that there is randomness in nature. Just experiment: try to sort a deck into ordered suit piles several times, or roll six sixes several times in a row. The results are probabalistic, not deterministic, and pretty much up to chance. If the results were deterministic they would not be random.

    Hopefully that explains why cheating at the game is not random.

    What makes PRNGs so non-random is how the results are computed, but that's not natural. And even then they fake it pretty nicely.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. rapid random number generation problem
    By Newton in forum C Programming
    Replies: 17
    Last Post: 09-19-2008, 02:08 PM
  2. Random number in range generation.
    By hebali in forum C Programming
    Replies: 19
    Last Post: 03-04-2008, 10:46 AM
  3. adding a number to a number
    By bigmac(rexdale) in forum C Programming
    Replies: 11
    Last Post: 10-24-2007, 12:56 PM
  4. random number between negative and positive number
    By anomaly in forum C++ Programming
    Replies: 6
    Last Post: 12-06-2003, 08:40 AM
  5. Random Number Generator
    By Ikurik in forum C++ Programming
    Replies: 16
    Last Post: 08-17-2003, 07:34 PM