How to generate random number each time?

Isn't it impossible for a computer to randomly generate numbers?

  • Theoretically a computer is totally logical and therefore shouldn't be able to generate random number without a mathematical equation. But how does the equation get it's variables? I suppose this could be done with the current date, and time, spread out as an integer. But if that is so it would be prone to repeated numbers and predictability. Theoretically, getting a random number should be impossible without seed, or a variable that already exists but changes very quickly. Even then, that's not random at all. So how does a computer generate random numbers? And is it even possible for it to be totally random in number generation?

  • Answer:

    Awesome question - you are right it, it is very hard for a computer to generate a truly random number. For non-security work where you just want a pseudo-random number, as you suspect developers often seed the generator with the current system time that change around every millisecond. For better randomness, some programs get their seed from user input - like observing how the mouse is moved, or the time taken between keystrokes to generate a seed. For high security applications, there is sometimes hardware that actually observes physical phenomena that are unpredictable and random as known to modern physics, things like decay of radioactive isotopes. These produce truly random numbers, at least as far as science knows thus far. In all cases, the number is then passed through an algorithm that scrambles the number, usually by iteratively performing modulo and power (like squaring, cubing) operations, and bit swapping. These algorithms are chosen to have outputs that have weak mathematical correlation with the input and where the output has a normal distribution. Together these prevent predictability and repetition, even for seeds that are easy to predict. Of course, every algorithm has its weaknesses, but the idea is a number only needs to be random enough to make mathematicians weep softly in their sleep.

Surt at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

you are totally right the computer can't generate random numbers, it generates something called pseudo random series usually there is a lot of algorithms to generate pseudo random variables for more details: http://en.wikipedia.org/wiki/Pseudorandom_number_generator but all of these methods depends on something called the "seed", which is usually defined from one of the system variables (date-time, ) or combination of them the pseudo random series are size limited, so the numbers will be repeated after some time finally, there is some real random numbers that depends on some natural phenomenon like: dice , coin flipping, thermal noise, he timing of actual movements of a hard disk read/write head, and radio noise the last two phenomenons can be used in the computer, but they are not used

There are two ways that computers can generate random numbers: You can create some sort of device that monitors a completely random natural event and sends its results to the computer. For example, you could place a piece of radioactive material in front of a Geiger counter and connect the Geiger counter to a computer. Since radioactive decay is random, the Geiger counter would create truly random numbers. This approach is pretty rare, because not many people have Geiger counters connected to their machines. You can create a formula that generates a pseudo-random number. When designing the formula, the idea is for it to produce a string of numbers that would look random to anyone who did not know what the formula is. Characteristics of a good formula include: No repetition: The sequence does not cycle around and repeat itself. Good numeric distribution: If the formula is producing random numbers between 0 and 9, the number of zeros, ones, twos, etc. that it produces should be roughly equal over a long period of time. Lack of predictability: You have no way to predict what the next number will be unless you know the formula and the seed (the initial value).

Well this is coming from someone who doesn't know much about computers, but I'm guessing "randomly generated numbers" is just a phrase or term of speech.

Most computers DON'T generate random numbers. They merely emulate random number generation essentially the way you theorized in your question. But does true randomness actually exist? Or does it just seem to, since we aren't even close to having a complete model of the universe yet? We really have no solid proof either way. Fun stuff to think about.

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.