Verifiable Randomness Documentation

Verifiable Randomness Systems

View the Project on GitHub blockrand-api/blockrand-js

Why Shuffling Is Hard: Hidden Bias in Card and Loot Systems

Description: How naive shuffle algorithms introduce measurable bias, and how to implement a provably fair, auditable shuffle using cryptographic randomness.

Why Shuffling Is Hard

Shuffling looks solved.

Take a list.
Randomize it.
Done.

In reality, most shuffles in production systems are biased — sometimes badly.

This document explains:

The Myth of “Random Sort”

One of the most common mistakes:

Sort items by random value.

Example pattern:

  1. Assign random() to each card
  2. Sort by that value

This feels random.
It is not.

Why Random Sort Is Biased

Sorting assumes:

None of these guarantees hold in practice.

Consequences:

This method is mathematically incorrect for shuffling.

The Only Correct Shuffle

The Fisher–Yates shuffle is the only proven method for uniform permutation.

Core idea:

If implemented correctly, every permutation has equal probability.

Where Fisher–Yates Still Fails

Even Fisher–Yates can be biased if:

The algorithm is correct.
The implementation often is not.

Modulo Bias in Shuffling

Typical index selection:

index = random() % (i + 1)

If random() does not produce a range divisible by (i + 1):

Across thousands of shuffles:

Deterministic Shuffle Model

A provably fair shuffle must:

Given the same seed:
The shuffle must always produce the same deck.

Entropy Derivation Per Step

Instead of calling random():

Use:

hash(seed : step)

Each step produces:

Anyone can recompute the shuffle offline.

Rejection Sampling for Index Selection

Correct index selection:

  1. Generate large entropy
  2. Define maxMultiple = (M / (i + 1)) * (i + 1)
  3. Reject values above it
  4. Modulo the rest

This guarantees uniform distribution.

Yes, it is slower.
Yes, it is correct.

Why Deterministic Shuffles Matter

In card games, loot drops, and raffles:

A deterministic shuffle allows:

Real-World Shuffle Failures

Observed in production:

Most were caused by:

Shuffling as a Verifiable Protocol

A fair shuffle is not:

It is:

Anything less is trust-based.

Key Takeaway

Shuffling is a cryptographic problem.

If:

Then the shuffle is unfair — even if it looks random.

BlockRand shuffle is fair.