How do random number generators work?

269 views

How do random number generators work?

In: 119

10 Answers

Anonymous 0 Comments

For random numbers you get a starting number, called a seed, and then perform a set of maths and bit manipulations to convert it to a new number. then that number is used as the seed for the next number and so on.

the kinds of manipulations done are swapping bits, inverting bits, multiplying by large prime numbers and taking the modulus. all things that make the resulting number seem unrelated to the previous.

a more modern approach is to take a hashing function, which is a function that takes an input and does similar manipulations to get an output, but with cryptographic security. this is slower, of course.

this means that given a seed, the same set of numbers are always produced. this can be useful if, for example you want to replay a computer game run to see if it was actually possible, or share some “random” artifact, or reproduce a set of tests.

sometimes you don’t want to be able to recreate the number ever, for example when making cryptographic keys or passwords. for these cryptographic random numbers you will definitely use a hash function in your generator and also get your seed carefully selected from the environment. things that get used for seeds like this: precise timings of things, network packets, keypresses, mouse movements, disk access. better are things that read the environment like radio receivers tuned to static. one system includes a high def video of a wall of lava lamps as it’s input to the random number generator.

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