# Category:Fisher-Yates shuffle

From LiteratePrograms

The **Fisher-Yates shuffle** is the most used algorithm for shuffling lists or arrays. In its original wording, you should get a random element from the original list into an accumulator until the original list is empty. In practice, a more convoluted wording is commonly used, which shuffles a list in-place:

- Let
be the list,**A**be its length,**N**–**A**_{1}be its elements. Let**A**_{N}be**i**.**N** - Let
be random between 1 and**r**(inclusive).**i** - If
is not equal to**i**, swap**r**and**A**_{r}.**A**_{i} - Decrease
by one.**i** - Repeat steps 2 through 4 until
equals 1.**i**

The algorithm complexity is O(n).

## Pages in category "Fisher-Yates shuffle"

This category contains only the following page.