Shuffle a List in Scala [duplicate]

夙愿已清 提交于 2019-12-05 10:46:44

问题


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.


回答1:


User Scala's Random class method shuffle:

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


来源:https://stackoverflow.com/questions/39990858/shuffle-a-list-in-scala

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!