Why it matters

Fisher-Yates is the standard shuffle. Bad variants (Naive) create bias; use the correct form.

Advertisement

The architecture

i from n-1 down to 1.

Swap i with random j in [0, i].

Uniform over permutations.

Fisher-Yates shuffleLoop ifrom n-1 down to 1Swapwith j in [0, i]Uniformn! orderingsNaive variant with j in [0, n) is BIASED — use Durstenfeld's version
Fisher-Yates shuffle.
Advertisement

How it works end to end

Durstenfeld's in-place form.

Uniform over permutations.

Language libs implement.