How Does Pseudorandom Number Generator (PRNG) Work?

A pseudorandom number generator is like a special kind of toy that makes up numbers without really thinking, it just follows rules.

Imagine you have a box with numbered marbles inside, and every time you shake the box, one marble pops out. That’s a random number! But if you always shake the box in the same way, you might get the same sequence of numbers each time. A pseudorandom number generator is like that box, it uses rules to make up numbers that look random, even though they follow a pattern.

How It Starts

A PRNG usually needs a starting point called a seed. Think of the seed like your favorite way to shake the box. If you start with the same seed, you’ll get the same sequence of marbles (numbers) every time.

Following Rules

Once it starts, the PRNG follows a simple rule, maybe it takes the last number and does some quick math to find the next one. It's like playing a game where each move depends on the last one you made. Even though it uses rules, the numbers still look random, just like how marbles might seem to pop out in no particular order, even if you shake the box the same way every time.

Take the quiz →

Examples

  1. A coin flip machine that always starts with the same flip, but looks random
  2. A game that uses a secret number to decide who wins
  3. A dice roll that repeats every time you play

Ask a question

See also

Discussion

Recent activity