Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shuffle a List in Scala [duplicate]

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.

like image 312
Deden Bangkit Avatar asked Oct 12 '16 05:10

Deden Bangkit


1 Answers

User Scala's Random class method shuffle:

scala.util.Random.shuffle(List(a,b,c,d))
like image 147
Nyavro Avatar answered Oct 15 '22 17:10

Nyavro