how do random number generators work?

814 views

how do random number generators work?

In: Technology

5 Answers

Anonymous 0 Comments

There are 2 types:
RNG (Random number generators)
pRNG (psueduo-random number generators, which try as best as possible to generate numbers which have similar properties as random ).

An example of an RNG is a real life dice. Other examples are coins, wheels, etc.

Can you REALLY make something truly random in a computer? Many will say no, but you can get close. There have been some examples listed in other posts here. Others examples are: the stock market price, radio-magnetic readings, etc.

Most random behaviour in computer programming is using pRNG

Let me give you an example of a really simple pRNG. Let’s say you want a random number between 1 and 10.

As suggested in other posts, what’s important to random numbers is a “Seed”. Think of a seed as the angle you are rolling your dice at. If you throw the dice the exact same way, it should give you exactly the same result. It’s the same as a seed, the same seed will give you the same result. A seed is what gets you started.

My method will be:
– write the current time as a number (including the seconds)
– add all the digits together
– if that number is greater that 10, add all those digits together
– repeat until there is a single digit.
– add one to the result.

So let’s take a seed of the time. The time at the moment is
12:58:44 so ill just say my seed is 125844.

Then ill add all the numbers together (1+2+5+8+4+4) = 24

The number is greater than 10 so ill add the digits together. (2+4) = 6

6 + 1 = 7

my result is 7

So, this is a legitimate pRNG, it generates numbers between 1-10. It may not be a very GOOD one, but it gives you an example of one. Now, real world pRNGs use much more complicated math, generally involving large prime numbers, modular arithetic and bit shifting (I wont go into those, but if you have grasped the general concept, you might be interested to google those)

You are viewing 1 out of 5 answers, click here to view all answers.