![](/img/trans.png)
[英]Sample a different number of random rows for every group in a dataframe in spark scala
[英]Generating two different random number simultaneously in Scala - Spark
有人可以幫助我在兩個范圍內生成兩個不同的隨機數嗎? 我試過了:
var a = Random.nextInt(S)
var b = Random.nextInt(K)
if (a == S || b == K){
a = S-1
b = K-1
}
(word,a,b)
但這會生成一些不在指定范圍內的數字。
從Random
文檔 :
def nextInt(n: Int): Int
返回一個偽隨機數,它從此隨機數生成器的序列中提取,在0(含)和指定值(不含)之間均勻分布的int值。
根據方法協定, nextInt
將始終返回從0到n - 1
的值,因此您的條件a == S || b == K
a == S || b == K
始終為假。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.