Overview
Fisher-Yates walks backward through a list and swaps each item with a random earlier item, including itself.
Randomly shuffles a list so every ordering is equally likely.
Compact metadata for implementation and discovery.
Fisher-Yates walks backward through a list and swaps each item with a random earlier item, including itself.
Quick facts
Runtime and memory behavior at a glance.
Best
O(n)
Average
O(n)
Worst
O(n)
Space
O(1)
j = random integer in [0, i]Chooses an unbiased partner for the current suffix position.
Show each position swapping with a random earlier position.
The inclusive random-index range is the detail that preserves uniformity.
What each reference supports for this entry.
Randomness reference for Fisher-Yates Shuffle's uniformity argument, recurrence, or random-selection procedure.
Good next jumps from the relationship graph, ranked for useful discovery.
Fisher-Yates requires a source of random indices.
Both sample without bias from discrete items.