Course contentsShow
← Data Science
Lesson 2056 of 2,14547. Reproducible ResearchFree lesson

Pseudorandom Number Generators

Learn how computers generate seemingly random numbers using deterministic algorithms and initial seed values.

Pseudorandom Number Generators

You'll learn how computers create seemingly random numbers through deterministic algorithms and seed values.

Computers can't generate truly random numbers on their own—they lack the unpredictability of rolling dice or flipping coins. Instead, they use pseudorandom number generators (PRNGs), which are mathematical algorithms that produce sequences of numbers that appear random but are actually completely deterministic.

How PRNGs Work

Think of a PRNG like a very complex recipe. You start with an initial seed value (like a starting ingredient), and the algorithm transforms it through mathematical operations to produce a number. That output becomes the input for the next number, creating a long chain of seemingly unrelated values.

Here's the key insight: given the same seed, a PRNG will always produce the exact same sequence of "random" numbers. This is why we call them pseudorandom—they're reproducible, not truly random.

Why This Matters in Data Science

This deterministic behavior is actually a feature, not a bug, for reproducible research. When you set a seed before shuffling data, sampling records, or initializing model weights, anyone can recreate your exact results by using the same seed. Without setting a seed, every run would produce different "random" choices, making your analysis impossible to verify or debug.

Common PRNGs in data science include the Mersenne Twister (Python's default for many years) and PCG (a modern, faster alternative). While they're not cryptographically secure, they're perfectly suitable for statistical simulations, data splitting, and model initialization.

Key Takeaway: Pseudorandom number generators use deterministic algorithms and seed values to create reproducible sequences of seemingly random numbers, enabling consistent results across repeated runs of data science workflows.