English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

How do the random number generators work in a computer? Also, if you know a link to the code that was used to build the generator, I would like to see it! Thank you very much.

2006-07-20 04:44:11 · 9 answers · asked by M 4 in Computers & Internet Programming & Design

I don't mean "functions" like how to use random(). I'm asking "how does it work?" Computers can't generate a 'true' random number, but I want to know how they do it, and why it's not entirely 'true'.

2006-07-20 04:52:14 · update #1

Also, if you use time to get a random number, then it's not random. When random, the user has no control.

2006-07-20 04:53:09 · update #2

9 answers

A lot of things can make a number random. I have seen people doing calls to the memory and it dumps random numbers from the memory. Because the contents of the memory always change, its always random. I have also seen programs that interact with the user, when the user moves the mouse or clicks a key on the keyboard it generates a random number based on that sequence, because the chances of the same mouse movement or the same sequence of keys being pressed in the exact timing order is random, thats how i have seen it done.

2006-07-20 05:50:30 · answer #1 · answered by Jewelie 2 · 0 0

Random numbers are generated by applying a transform f(x) on a base seed x. The transform ensures that the random number is generated in the specified range. After each call to rand() [or f(x)] the function modified its internal state to reflect the previous random number so that the next number takes this state change into account.
There is no truly random number in the sense that the same seed will generate exactly the same sequence of random numbers. The common technique is to uses the system time as the seed as this ensures uniqueness.
You will find some implementations of random numbers at:
http://www.agner.org/random/
You can search the web for other implementations. There are plently available. Hope this helps.

2006-07-20 06:03:04 · answer #2 · answered by zero 2 · 0 0

The concept of "random" number in mathematics is pretty interesting. you see, computers cant really generate "random" numbers and there is no such thing as a "random" number..

computers used a mathematical formula so complex that it is hard to predict the outcome. depending on the complexity and the number input, a "random" number can be generated by a computer program. the input can be anything from the time of the day to the current day in a year..

It's pretty hard to actually create a "random" computer program because if we are not proficient mathematicians, the outcome of the random number can be predictable therefore it is best to use prebuilt functions rather than coding one yourself...

hope that helps!

2006-07-20 05:34:18 · answer #3 · answered by Anonymous · 0 0

Well in .NET I use System.Security.Cryptography class to generate random numbers because I want only random UNIQUE Numbers and so far I have not got a duplicate random number. So use this class.

2006-07-20 05:09:18 · answer #4 · answered by v_navin 2 · 0 0

If you want a truly random number then multiply the generated random number by time. Usually seconds.

2006-07-20 04:51:53 · answer #5 · answered by AnalProgrammer 7 · 0 0

A computer can't generate a "true" random number, because there must be a program written to tell the computer how to do it.

See the link for more info...

2006-07-20 04:49:53 · answer #6 · answered by Jared Z 3 · 0 0

it all depends on what programming language you are using.

for me though when i have to generate a random number i use a date and time stamp and just put some calculations to it to get a random number.

2006-07-20 04:49:52 · answer #7 · answered by . 3 · 0 0

It uses Pi. 3.141592..... It calculates it to a particular level and then grabs the numbers (like every other one, etc.)

2006-07-20 04:56:33 · answer #8 · answered by Todd V 3 · 0 0

use rand() number generator command...:)

2006-07-20 05:07:47 · answer #9 · answered by BoB-SeriouS 2 · 0 0

fedest.com, questions and answers