2013-02-04 18 views
6

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

回答

7

System.nanoTime类型为longtakeSample预期的种子为Int类型。因此,takeSample(..., System.nanoTime.toInt)应该工作。

+1

在scala中'.toInt'应该优先于'.intValue' –

+0

@RégisJean-Gilles谢谢,更正。 –

1

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