在 Scala 中打乱列表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39990858/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 08:43:56 来源:igfitidea点击:
Shuffle a List in Scala
提问by Deden Bangkit
I have question to for shuffle list in scala using scala.util.Random.
我对使用 .scala 的 shuffle 列表有疑问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 colorto be random order of val a, b, c and d.
所以我希望val color是 的随机顺序val a, b, c and d。
回答by Nyavro
User Scala's Random class method shuffle:
用户 Scala 的 Random 类方法随机播放:
scala.util.Random.shuffle(List(a,b,c,d))

