Question:
How does "random" number command work on a computer? Is it really random?
Phil
2010-01-19 10:08:30 UTC
Is there some way in determining the next random number?
Eight answers:
Mantis
2010-01-19 10:28:58 UTC
Random number on a computer are only sort of random. They are random enough for most purposes, though, and without knowing what the original seed is and what algorithm is used (there are many) you're unlikely to be able to determine the next number... especially if you only have one or two numbers to start with.



The way it works is to start out with a seed. The seed can be anything. Most programmers use the current time in milliseconds, as this produces a seed that is hard to reproduce and well outside of the user's control. This value is then run through an equation to produce the first random number. Exactly how that equation works depends on what library is used, but it is deterministic, which means that if you give the same random number engine the same seed, it'll always produce the same 'random' number. The new random number is the basis for the next random number, which is the basis of the number after that, and so on.



So if you knew the initial seed and knew how many random numbers had been generated before, then you could produce the next value. But just knowing the last-produced value won't tell you anything. (If you had the last twenty or thirty produced values and plenty of time on your hands, you could try all the random number seeds and generate a few thousands numbers per seed looking for that pattern, but that's unlikely to be useful).



These random numbers are generally between 0 and 65535, so the programmer usually divides these numbers to produce something useful to them. For example, dividing by 6 and taking the remainder (rand() % 6) will give you a die roll. This makes it even harder to determine what the random number generator actually produced, which adds to the apparent randomness of the generator.



So to summarize the answers to your questions, it's only pseudorandom, and unless you know the seed and how many numbers have been produced so far, you're not likely to be able to determine the next value.



Hope this helps.
Pfo
2010-01-19 10:13:14 UTC
No, it's not really random. Computers can't generate a truly random number, because some mathematical equation is always used to generate that number. Some popular ways of doing this are using the current time as a variable in the equation to generate a random number, or using a "seed", a predetermined number as the variable in the equation. Once a seed is chosen, it is possible to predict what the random numbers will be if the random number algorithm is known.



Even people don't truly choose random numbers. If you ask someone to choose a random number, there is nearly a 100% probability they will choose a positive whole number less than 100. There is an entire space of negative numbers equal in size to the positive ones, no one ever chooses a random number from these. Their are also as many numbers between 0 and 1 (fractions) as their are real numbers, no one ever chooses these either. Their are also complex numbers (i, or sqrt(-1)), no one chooses these either.
Michael from UK
2010-01-19 10:14:50 UTC
There are typically two forms of random numbers.



Standard 'pseudo-random' numbers, where a seed number (usually set from the time) is used to cycle through a sequence of numbers. So, given the same seed, the same sequence of "random numbers" is created. They are just numbers in an odd sequence really.



Then there are 'secure random numbers' which are used when a random number is required which will be used to pass data around securely - typically for IP message streams. These do not follow a sequence and a 'more random' (if that makes any sense).



There is no such thing as a truly random number on a computer.
anonymous
2010-01-19 10:28:26 UTC
My professor (A.S.Tanenbaum; this one: http://www.amazon.com/dp/0130661023/) used to say that the only way to generate truly random numbers would be to attach a Geiger counter to your computer and count the number of hits during an interval, whilst pointing it into space. Or something like that --it's been a loooong time...
anonymous
2016-11-08 04:09:09 UTC
desktops can no longer make random alternatives in any respect. they have instructions fed into them and the numbers are the two calculated utilising a formula, or utilising pre-fed sequences. in case you examine any solid archives e book, this element is suggested very fairly. although, the formula or pre-fed sequence is many times from a random form table.
?
2010-01-19 10:12:23 UTC
It uses a mathematic formula that bases the result on the previous result.



No, and by some physics theories, nothing can be truly random.



Yes, if you know the formula, which changes between implementetations.
anonymous
2010-01-19 10:12:13 UTC
No it's not really random.
anonymous
2010-01-19 10:11:51 UTC
just like drawin numbers out of a hat


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...