scala> Random.shuffle((1 to 10).toSet)
res10: scala.collection.immutable.Set[Int] = Set(5, 10, 1, 6, 9, 2, 7, 3, 8, 4)
scala> Random.shuffle((1 to 10).toSet)
res11: scala.collection.immutable.Set[Int] = Set(5, 10, 1, 6, 9, 2, 7, 3, 8, 4)
scala> Random.shuffle((1 to 10).toSet)
res12: scala.collection.immutable.Set[Int] = Set(5, 10, 1, 6, 9, 2, 7, 3, 8, 4)
scala> Random.shuffle((1 to 10).toList)
res13: List[Int] = List(3, 9, 8, 5, 7, 6, 10, 2, 1, 4)
scala> Random.shuffle((1 to 10).toList)
res14: List[Int] = List(5, 10, 2, 9, 4, 7, 8, 6, 1, 3)
scala> Random.shuffle((1 to 10).toList)
res15: List[Int] = List(5, 9, 10, 6, 8, 3, 4, 1, 7, 2)
Così shuffle può gestire le liste bene, ma non le serie? I set non possono essere mischiati? Perché res10 == res11 == res12?Comportamento di shuffle su Set vs List utilizzando scala.util.Random
Il tuo reclamo non riguarda il comportamento di Random, ma piuttosto il comportamento di Set. Il contratto Set non implica la conservazione dell'ordine, consentendo convenientemente ottimizzazioni come il backup del Set con una tabella hash, quindi chiamareSet è un invito a riordinare la tua raccolta. –