21

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.

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Deden Bangkit
  • 598
  • 1
  • 5
  • 19
  • 2
    You've asked basically the same question three times now. Are you not getting the answers you need? (http://stackoverflow.com/questions/39989771/scala-random-list-of-val-order, http://stackoverflow.com/questions/39981539/scala-random-string) – The Archetypal Paul Oct 12 '16 at 05:47
  • Instead of shuffle.List(a,b,c,d) the right thing is shuffle(List(a,b,c,d)) – Carlos Saltos Apr 19 '19 at 09:13

1 Answers1

66

User Scala's Random class method shuffle:

scala.util.Random.shuffle(List(a,b,c,d))
Nyavro
  • 8,806
  • 2
  • 26
  • 33