请教Random类的Random r=new Random()和Random r=new Random(seedValue)有什么区别

   阅读
请问Random类的Random r=new Random()和Random r=new Random(seedValue)有什么区别?
设置随机数生成器的种子有什么用?不设置不行吗?谢谢了
------解决思路----------------------
Random r=new Random()
每次运行程序得到的随机数序列都是一样的。
例如第一次运行程序得到的随机数是 2, 4, 1, 5, 7
那么重启程序,再次得到的随机数还是2, 4, 1, 5, 7

Random r=new Random(seedValue): 
每次运行程序时seedValue不一样,得到的随机数序列不一样,一般会这么用
Random r=new Random(System.nanoTime()): 
------解决思路----------------------
引用:
Random r=new Random()
每次运行程序得到的随机数序列都是一样的。
例如第一次运行程序得到的随机数是 2, 4, 1, 5, 7
那么重启程序,再次得到的随机数还是2, 4, 1, 5, 7

Random r=new Random(seedValue): 
每次运行程序时seedValue不一样,得到的随机数序列不一样,一般会这么用
Random r=new Random(System.nanoTime()): 


2楼说反了吧。只有传入了固定的随机种子才能够得到固定的随机序列。

Random产生的随机数实际上属于伪随机数,是按照一定算法计算出来的。构造方法如果没有传入随机种子的话,系统会默认采用系统时间作为随机种子。
以下为Random类的源码


    /**
     * Creates a new random number generator. This constructor sets
     * the seed of the random number generator to a value very likely
     * to be distinct from any other invocation of this constructor.
     */
    public Random() { this(++seedUniquifier + System.nanoTime()); }
    private static volatile long seedUniquifier = 8682522807148012L;

    /**
     * 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}.
     *
     * <p>The invocation {@code new Random(seed)} is equivalent to:
     *  <pre> {@code
     * Random rnd = new Random();
     * rnd.setSeed(seed);}</pre>
     *
     * @param seed the initial seed
     * @see   #setSeed(long)
     */
    public Random(long seed) {
        this.seed = new AtomicLong(0L);
        setSeed(seed);
    }
阅读