This question already has an answer here:
- How Does Java Produce a Random Number? 3 answers
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+" ");
}
}
The result is :
5 8 7 3 4 4 4 6 8 8
I already look to Java Documentation the formula for updating seed is
(seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1)
which in this case is equal 0x5DEECE678L
in my case
and returning
(int)(seed >>> (48 - bits))
and if we use public int nextInt(int bound)
the result should be 4
Aucun commentaire:
Enregistrer un commentaire