हिंदी में देखें |

PC Tips

Random Number


Contents :-

How Computer Generates Random Number?

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).

Here's an example of a simple random-number formula:

int rand()
random_seed = random_seed * 1103515245 +12345;
return (unsigned int)(random_seed / 65536) % 32768;

This formula assumes the existence of a variable called random_seed, which is initially set to some number. The random_seed variable is multiplied by 1,103,515,245 and then 12,345 gets added to the product; random_seed is then replaced by this new value. This is actually a pretty good pseudo-random number generator.

It has a good distribution and it is non-repeating. If you use it to produce random numbers between 0 and 9, here are the first 20 values that it produces if the seed is 10:


If you have it produce 10,000 values between 0 and 9, here's the distribution:

0 - 1015
1 - 1024
2 - 1048
3 - 996
4 - 988
5 - 1001
6 - 996
7 - 1006
8 - 965
9 - 961

Any pseudo-random number formula depends on the seed value to start the sequence. If you start with the same seed, you will get the same sequence of values from the formula.

So if you give the rand() function shown above the seed of 10 on one computer and look at the stream of numbers it produces, it will be identical to the stream of numbers produced on any computer that runs it with a seed of 10.

In the case of the Global Positioning System, this reproducibility is used as a way to give each satellite a predictable but different pattern of values that the GPS receiver can track.

To create a random and unpredictable sequence, the seed must be a truly random number. To get this truly random number for the seed, most programs use the current date and time, converted to an integer value (for example, converted to the number of seconds that have elapsed since January 1, 1970). Since this is a different number every time you start the program, it makes a good seed.

.....Previous     Same     Next.....

Tags- Random Number | What is random number example? | How do you calculate random numbers? | What is the most random number? | Is it possible to generate a random number? | How is random number generated? | What is a random number table used for? | How do you generate random numbers? | What is meant by pseudo random number? | Why are random numbers used in sampling? | What is the random number generator? | What are the properties of random numbers? | What is random in statistics? | What is pseudo random sequence generator? | How do you generate a random number in C++? | What is random number in Java? | How are pseudo random numbers generated? | How do you generate random numbers in Python? | How do you generate a random number in Java? | What is random in Python? | How do you raise user defined exceptions in Python? | What is random seed in Python? | Is random Randint inclusive? | What does random Randint mean? | What is Xrange in Python? | What is Randint in Python? | Which keyword is used for function? | What is loop in Python? | What is the IF function in Python? | Which languages does Python owe its origin to? | Why Python doesn t have switch? | What does == mean in Python? | What does () mean in Python? | What does D mean in Python? | What does this do in Python? | What is a decorator in Python? | What does += mean in Python? | What does def mean in Python? | Python what is def? | What does def stand for in texting? | Is equal to Python? | Is Python a keyword? | Is Python an operator? | What is the difference between? | What is the difference between I love you and love you? | What is difference between Miss and MS? | What is difference between love and like? | Can you love someone and not like them? | What is empty love? | Is like and love the same thing? | What does having feelings for someone mean? | What is the difference between I love you and I like you? | What is the difference between infatuation and love?

Home|Indian Doctors|Indian Hospitals|Utility|Career|Electronics|Family|General|Health|PC Tips|Technology|About Us|About Admin|Feedback|Apply For Job Computer Courses|Login| Created by - Er. Sanjay Singh