指定和观察到的伪随机数生成之间的差异

时间:2016-09-05 13:27:18

标签: java random

public static void main(String[]args) throws InterruptedException{
    Random r = new Random(1);
    for (int i = 0;i<10;i++){
        int n = r.nextInt(10);
        System.out.print(n+" ");

    }
}

结果是:

  

5 8 7 3 4 4 4 6 8 8

我已经查看Java Documentation 更新种子的公式是

(seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1)

在这种情况下,在我的情况下等于0x5DEECE678L

并返回

(int)(seed >>> (48 - bits)) 

如果我们使用 public int nextInt(int bound)

结果应为4

0 个答案:

没有答案