Randomness in Software Is Harder Than You Think

May 1, 2026

Building a dice roller seems like a 5-minute project. And it is โ€” if you just use Math.random(). But the moment you start thinking about randomness, you fall into a fascinating rabbit hole.

Pseudo-Random vs True Random

Math.random() is a pseudo-random number generator (PRNG). It uses a deterministic algorithm seeded with some initial value. Given the same seed, you get the same sequence. That's fine for games and UI but terrible for cryptography.

For crypto, you need crypto.getRandomValues() which pulls from the OS's entropy pool โ€” mouse movements, disk timing, network noise. True randomness from physical chaos.

The Birthday Problem

If you generate random IDs, collisions happen way sooner than you'd expect. With just 23 people in a room, there's a 50% chance two share a birthday. Same principle applies to random UUIDs, session tokens, and hash functions.

Fun With Dice

I built a dice roller that supports multiple dice types (D4 through D20), lets you roll multiple dice at once, and shows a roll history with statistics. Nothing groundbreaking, but surprisingly satisfying to use.

Try it: Dice Roller

Takeaway

Randomness is one of those topics where the surface is simple but the depth is infinite. Build a dice roller, then go read about Mersenne Twister and you'll be hooked.