Java中Random在循环和不在循环中产生随机数的问题?

如代码中,为何for循环中生成的10次随机数a,b是每次不同的,但是我每次运行,产生的c和d却是固定不变的?
我不是要不同,我是把for中的10次循环当做运行10次(这样理解我不知道对不对),它第1次和第2次(每次是这个意思)都不一样,但是每次运行后c和d 是一样的 。

import java.util.Random;

public class Test00 {
    public static void main(String[] args) {
        Random rd = new Random(99);
        Random rt = new Random(99);
        int a;
        int b;
        for(int i=0;i<10;i++) {
             a = rd.nextInt(55);
             b = rt.nextInt(55);
            System.out.println("第"+i+"次"+a+" "+b);
        }
        int c = rd.nextInt(55);
        int d = rt.nextInt(55);
        System.out.println(c+" "+d);

    }

}
```运行结果
第0次47 47
第1次43 43
第2次34 34
第3次46 46
第4次0 0
第5次37 37
第6次29 29
第7次11 11
第8次45 45
第9次44 44
33 33   //点击10次,此处依旧是33 33

不可能,你的a和b每次肯定是相通的,要想不同请去掉99

看下类的注释:

  • If two instances of {@code Random} are created with the same
  • seed, and the same sequence of method calls is made for each, they
  • will generate and return identical sequences of numbers. In order to
  • guarantee this property, particular algorithms are specified for the
  • class {@code Random}.

  • 再理解下 public Random()
    public Random(long seed)

    • 这两个构造方法的意义。
    • seed 参数的含义:
    • Creates a new random number generator using a single {@code long} seed.
    • The seed is the initial value of the internal state of the pseudorandom
    • number generator which is maintained by method {@link #next}.