在Scala中随机播放列表 [英] Shuffle a List in Scala

查看:68
本文介绍了在Scala中随机播放列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有疑问要使用scala.util.Random在scala中的随机播放列表.

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

例如我有

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 ;(

所以我希望val colorval a, b, c and d的随机顺序.

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

推荐答案

用户Scala的随机类方法改组:

User Scala's Random class method shuffle:

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

这篇关于在Scala中随机播放列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆