ELi5 , how do random number generators work?

727 views

How is it different than the program just choosing the number it wants within range?

In: 6

11 Answers

Anonymous 0 Comments

Simples RNG works as follows:

1. take a number between 0 and 1, with lots of decimals.

2. Multiply by a really large number

3. Keep the decimals, drop the integer part (e.g. 123.4567 becomes 0.4567)

4. You have another number between 0 and 1, and there is no easy way to predict its range if number in step 2 was indeed large.

5. if you want more random numbers, take the number from step 4 and use it to repeat steps 2-3.

NUmber from step 1 is the “seed”. Same seed means same sequence of “random” numbers. Which is useful for debugging. For a truly random choice of seed, take system clock and use it decimals from seconds counter.

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