【发布时间】:2015-05-15 19:35:59
【问题描述】:
scala
Welcome to Scala version 2.10.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_79).
Type in expressions to have them evaluated.
Type :help for more information.
scala> 300 to 1000 toSet
warning: there were 1 feature warning(s); re-run with -feature for details
res0: scala.collection.immutable.Set[Int] = Set(645, 892, 809, ...)
// 问题#1:我预计再次运行时顺序会有所不同。它与 res0 的顺序相同。 所以我想,可能是由于不同的原因(系统熵等),范围太小而无法区分。
scala> 300 to 1000 toSet
warning: there were 1 feature warning(s); re-run with -feature for details
res1: scala.collection.immutable.Set[Int] = Set(645, 892, 809, ...)
// 问题#2:这太奇怪了。即使在洗牌后,我也看到了相同的顺序。为什么?
scala> scala.util.Random.shuffle((300 to 1000).toSet)
res2: scala.collection.immutable.Set[Int] = Set(645, 892, 809, ...)
【问题讨论】: