CrazyEngineers
  • How Does A Random Number Generator Work?

    Shashank Moghe

    Shashank Moghe

    @shashank-94ap1q
    Updated: Oct 24, 2024
    Views: 2.3K
    I always had a query. I have really good software development background (although I am a Mechanical Engineer by education & profession). How do random number generators work?

    A thought experiment: Have two systems (one much faster than the other) ready with the same rand(). Start the program at the same time on both the systems. The slower system computes a random number with whatever logic it adopts and takes time "x". The faster system can generate the same number in time less than "x". So what is totally randomly generated for the user of the slower system is not so random after all, if he calls up the user of the faster system as gets to know the number beforehand.

    Please provide answers and neglect the seemingly absurd thought experiment.
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Ramani Aswath

    MemberSep 10, 2014

    I do not get this.
    In an excel sheet you fill as many cells as you want with the rand() function. They all get filled with different random numbers at the same time.
    Are you sure? This action cannot be undone.
    Cancel
  • Shashank Moghe

    MemberSep 11, 2014

    A.V.Ramani
    I do not get this.
    In an excel sheet you fill as many cells as you want with the rand() function. They all get filled with different random numbers at the same time.
    All I am saying is, what is the underlying logic in generating a random number? There must be some logic that has to be used, and that undermines the whole point of it being random. A faster computer can run the same logic and can provide you with this "random" number while the slower computer still works on the same rand() program. Turns out, for the slower computer, the number computed isn't random at all (since it is already outputted by the faster computer).

    The concept of randomness, to me, is how Erwin Schrodinger used in the famous cat experiment. He assumed a radioactive substance so small in amount that in an hour probably only one atom decays (or may be doesn't). Depending on that decay event (or the lack of it), the fate of the cat is decided. Now that, is true randomness.

    To cut the long story short, if logic (no matter what logic, as long as its logic or a sequential chain of ideas) is employed, a random number is never truly generated.

    I am sorry for this pathetic explanation, but I am sure you get my point here. I appreciate your inputs.
    Are you sure? This action cannot be undone.
    Cancel
  • Ramani Aswath

    MemberSep 11, 2014

    The rand() function generates a 'pseudorandom' number not a true random number. However, it would happen rarely that two machines (whatever their speeds) would produce the same output.
    I do not know the process. Some 'seed' is used, which may be chosen in some way by the programme which further processes this seed to generate the pseudo random number.
    This article gives some more info:
    <a href="https://www.random.org/randomness/" target="_blank" rel="nofollow noopener noreferrer">RANDOM.ORG - Introduction to Randomness and Random Numbers</a>
    Are you sure? This action cannot be undone.
    Cancel
  • Shashank Moghe

    MemberSep 11, 2014

    A.V.Ramani
    The rand() function generates a 'pseudorandom' number not a true random number. However, it would happen rarely that two machines (whatever their speeds) would produce the same output.
    I do not know the process. Some 'seed' is used, which may be chosen in some way by the programme which further processes this seed to generate the pseudo random number.
    This article gives some more info:
    <a href="https://www.random.org/randomness/" target="_blank" rel="nofollow noopener noreferrer">RANDOM.ORG - Introduction to Randomness and Random Numbers</a>

    Excellent article. It confirms that the functions like rand() are pseudo random number generators. If the "seed" is the same, a faster computer will yield the same number faster than the slower one. This is what I meant. Now we know (and the article confirms) that these numbers are not truly random, but can be reproduced with the same starting "seed" and periodic (the sequence of numbers generated is repeatable).

    This brings me to my next question, although this time I have better knowledge (thanks to A.V Ramani sir) - Is there a true random number generator function?
    Are you sure? This action cannot be undone.
    Cancel
  • avii

    MemberSep 11, 2014

    ^There is no true random generator, afaik.
    Are you sure? This action cannot be undone.
    Cancel
  • pratap singh, upendra

    MemberSep 15, 2014

    The machine starts with a particular number(at its own discretion) and applies certain algorithm like least squares method etc. to generate further sequence of random numbers.

    Also the two machines may start with two different numbers and at the same time they may also make use of different algorithms to further their sequence.
    So, it is fair enough to state that two machine will rarely generate the same set of random numbers after every input pulse given to them.

    Also remember that for a particular machine, random numbers in the sequence are not mutually independent. They are always linked through some algorithm( the same algorithm that was used to generate the sequence). For this reason, random numbers are not strictly random, rather they are pseudo-random numbers.
    Are you sure? This action cannot be undone.
    Cancel
  • Shashank Moghe

    MemberSep 15, 2014

    proffy
    The machine starts with a particular number(at its own discretion) and applies certain algorithm like least squares method etc. to generate further sequence of random numbers.

    Also the two machines may start with two different numbers and at the same time they may also make use of different algorithms to further their sequence.
    So, it is fair enough to state that two machine will rarely generate the same set of random numbers after every input pulse given to them.

    Also remember that for a particular machine, random numbers in the sequence are not mutually independent. They are always linked through some algorithm( the same algorithm that was used to generate the sequence). For this reason, random numbers are not strictly random, rather they are pseudo-random numbers.

    Well, I am getting opposing ideas from your reply. Anyhow, I don't quite digest the idea that a defined flow of logic can lead to a truly random number. Even when you say the "seeds" can be randomly selected, I believe even this random selection has some logic. The point being, you cannot truly have a random number if you have written the code to generate one.

    One stupid idea I had when I used to use the rand() a lot was that the code made use of the slight fluctuations in voltage from the grid to somehow compute the random numbers. These fluctuations are transient and hence can be fairly random. But then again, I thought if a supercomputer connected to the grid had the rand(), it would already know the output, much before my company PC could generate one 😀
    Are you sure? This action cannot be undone.
    Cancel
  • Ramani Aswath

    MemberSep 15, 2014

    shashank Moghe
    Excellent article. Is there a true random number generator function?
    The later part of the article does discuss this issue and shows why it is a cumbersome time consuming process. All TRNGs require an external random event input (like ambient noise).
    Are you sure? This action cannot be undone.
    Cancel
  • Shashank Moghe

    MemberSep 15, 2014

    A.V.Ramani
    The later part of the article does discuss this issue and shows why it is a cumbersome time consuming process. All TRNGs require an external random event input (like ambient noise).
    I get it is cumbersome, and probably even expensive. But the question was to whether there is capability on my work desk PC to generate a truly random number. And I guess I got the answer, thanks to the article you shared and other valuable responses from CEans.
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register