This may very well be the only question I ever ask on this stackexchange site. In programming there are many different ways to generate random numbers depending on different languages. What has been bothering me for a while now, however, is HOW can anything computer generated be random? I found this post however it wasn't very well received and it said to broad or to many possible answers. However the way I see it there is only one possible answer, how it works! I mean to say that someone with a computer background should be able to answer this so it isn't like I am asking for your opinion. As a final note I would like to apologize if I am in the wrong forum.


3 Answers 3


They can and can't depending on the computer. Usually, it's a pseudorandom algorithm. One of the earliest algorithms was basically just to perform a series of basic arithmetic (multiply, divide, add, subtract, modulo) on a number called a seed, and take the middle numbers, or something like that. The numbers appear random, but after a certain number of trials, the same cycle will repeat itself.

Which means that they can't use a PRNG to encrypt your password. PRNGs usually use the system time as the seed, so if the attacker know the approximate time your password was encrypted (account creation time, password change time), they can just generate a small range of passwords using that time range, and try all the generated passwords instead of having to generate all possible combinations allowed.

If you've ever gone to www.random.org, you'll probably see that they generate truly random numbers. That's because they use devices to collect atmospheric noise, or some kind of noisy atmospheric data, and use that.

I'm not an expert on this, but I think some OSes might also collect data from user's mouse movement and keyboard presses along with a PRNG to generate numbers secure enough to encrypt passwords with

  • 2
    A good PRNG won't be seeded by the time, but can still be seeded from a relatively small amount of information (that's impractical to brute-force, but is occasionally guessable if it comes from a bad source).
    – user253751
    Mar 20, 2015 at 1:24

They don't

They use algorithms known as Pseudo-Random Number Generators (PRNGs). These always produce the same sequence of numbers unless you provide a unique "seed" number to start them with.

A seed number can be created from a combination of relatively random sources - for example the last few digits of the milliseconds of the current time, the last few motions of the mouse pointer.

The result is a sequence of numbers that, for many purposes, is sufficiently like a random sequence to be unpredictable.

  • wow I had never even though of using something as miniscule as the current time in milliseconds I had just assumed that any method used to generate a random number couldn't possibly be random. Mar 19, 2015 at 23:06

Here's a code snippet from one of my assignments. It generates random numbers then checks if the random number has already been placed in the array and if it hasn't then it is allowed to go in and if not it isn't used.

public static int[] RandomArray(int RandArrayNValue)
        int[] array = new int[RandArrayNValue];

        Random rand = new Random();

        for (int i = 0; i < RandArrayNValue; i++)
            array[i] = i + 1;


        for (int i = array.Length - 1; i >= 0; i--)
            int Store = rand.Next(i);

            int TempStore = array[Store]; 

            array[Store] = array[i];

            array[i] = TempStore;
            Console.WriteLine(" " + array[i]);
        return array;
  • 1
    The OP is aware of how random numbers work at this level: "In programming there are many different ways to generate random numbers depending on different languages." The question is about how anything coming from a computer can really be random when a computer is completely deterministic (i.e. given input A, we always get output B).
    – tsleyson
    Mar 20, 2015 at 6:20
  • 1
    Random() isn't magic--this question is about how it works.
    – NReilingh
    Mar 22, 2015 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.