Apex › Storage & databases

Shuffle bias — Fisher–Yates vs the naive shuffle

The one-character bug that makes the popular "swap each index with any random index" shuffle provably biased — while the correct Fisher–Yates shuffle is perfectly uniform. Run thousands of shuffles and watch a bias pattern emerge in the naive heatmap while Fisher–Yates stays flat, with the exact counting argument for why.

More in Storage & databases