Why is this code is not shuffling the list?

songName.toMutableList().shuffle(Random())

It is shuffling, but toMutableList() creates new list which you then shuffle.

1 Like

@MikibeMiki
I have changed the code to songName.random() and still not working

Random() function returns random element from list or array.

1 Like

@MikibeMiki
So what can I do to shuffle all the values in the list

I recommend to just write this:

val shuffledSongNames = songNames.shuffled()

It will create a new read-only list with already shuffled elements.

1 Like