Shuffle a List in Scala

Deden Bangkit picture Deden Bangkit · Oct 12, 2016 · Viewed 14.1k times · Source

I have question to for shuffle list in scala using scala.util.Random.

For example I have

val a = cyan
val b = magenta
val c = yellow
val d = key

val color = Random.shuffle.List(a,b,c,d).toString //but it doesn't work ;(

so I want the val color to be random order of val a, b, c and d.

Answer

Nyavro picture Nyavro · Oct 12, 2016

User Scala's Random class method shuffle:

scala.util.Random.shuffle(List(a,b,c,d))