This article explores different ways to shuffle a list in Kotlin.

1. Using shuffle() function

The simplest and fairly efficient solution is to randomize a list is to use the native function shuffle().

Download Code

2. Using Fisher–Yates Shuffle Algorithm

Following is an implementation of Fisher–Yates shuffle algorithm, which shuffles the list from the highest index to the lowest index:

Download Code

 
The following is an equivalent version of the Fisher-Yates Shuffle algorithm, which shuffles the list from the lowest index to the highest index:

Download Code

That’s all about shuffling a list in Kotlin.