7

我正在尝试在SparktakeSample()中使用该函数,参数是 -数据、要采集的样本数和种子。但我不想使用种子。我想每次都有不同的答案。我无法弄清楚我该怎么做。我尝试使用作为种子值,但它给出了一个错误,因为我认为数据类型不匹配。有没有其他类似的功能可以在没有种子的情况下使用?或者我可以使用任何其他实现,以便每次都能得到不同的输出。System.nanoTimetakeSample()takeSample()

4

3 回答 3

8

System.nanoTimeis of type long,所期望的种子takeSampleis of type Int。因此,takeSample(..., System.nanoTime.toInt)应该工作。

于 2013-02-04T13:56:20.047 回答
1

System.nanoTime返回 Long,而 takeSample 需要一个 Int。
您可以将scala.util.Random.nextInt作为种子值提供给 takeSample 函数。

于 2013-02-04T13:54:50.930 回答
1

从 Spark 版本 1.0.0 开始,该seed参数是可选的。请参阅https://issues.apache.org/jira/browse/SPARK-1438

于 2014-12-08T14:27:59.057 回答