> For the complete documentation index, see [llms.txt](https://trizen.gitbook.io/sidef-lang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trizen.gitbook.io/sidef-lang/programming_tasks/k/knuth_shuffle.md).

# Knuth shuffle

```ruby
func knuth_shuffle(a) {
    for i (a.len ^.. 1) {
        var j = i.irand
        a[i, j] = a[j, i]
    }
    return a
}

say knuth_shuffle(@(1..10))
```

#### Output:

```
[5, 8, 4, 7, 10, 2, 9, 3, 1, 6]
```
