因为你的类名跟Jdk自带的Random重复,导致优化引入你定义的Random,如果你想强制引用Jdk的Random需要使用包名.类型形式
如果不传参数默认会把当前时间作为种子。
public Random() {// Note: Using identityHashCode() to be hermetic wrt subclasses.
setSeed(System.currentTimeMillis() + System.identityHashCode(this))
}
在java中所谓的随机数只是通过对种子进行一些算数运算得到的,所以又叫伪随机数
protected synchronized int next(int bits) {seed = (seed * multiplier + 0xbL) & ((1L << 48) - 1)
return (int) (seed >>> (48 - bits))
}
public int nextInt() {
return next(32)
}
由于生成的是伪随机数,所以在传入的种子很重要。
当不传入种子时,因为每次运行都会使用当前时间,而时间是一直在变的,所以每次运行时的种子也是在变的,因此你看到的结果是随机的。