Random
public Random(long seed)使用单个 long 种子创建一个新的随机数生成器。该种子是伪随机数生成器的内部状态的初始值,该生成器可通过方法 next(int) 维护。 
调用 new Random(seed) 等效于:  Random rnd = new Random();
 rnd.setSeed(seed);
参数:
seed - 初始种子
另请参见:
setSeed(long)问题:
帮我解释一下这段话是什么意思,“单个 long 种子”是什么?
Random rand = new Random(47)是什么意思呢?

解决方案 »

  1.   

    带有种子,每次运行结果相同,
    不带种子,实际上是以当前时间做种子,每次运行结果不同。
    If you create a Random object with no arguments, Java uses the current time as a seed for the random number generator, and will thus produce different output for each execution of the program. However, in the examples in this book, it is important that the output shown at the end of the examples be as consistent as possible, so that this output can be verified with external tools. By providing a seed (an initialization value for the random number generator that will always produce the same sequence for a particular seed value) when creating the Random object, the same random numbers will be generated each time the program is executed, so the output is verifiable.1 To generate more varying output, feel free to remove the seed in the examples in the book.
    选自《编程思想》
      

  2.   

    Random rand = new Random(47)是什么意思呢?声明了一个rand对象,并赋予初值,使随机数固定。47是习惯写法,也可以是别的数。
    个人意见
      

  3.   

    If you create a Random object with no arguments, Java uses the current time as a seed for the random number generator, and will thus produce different output for each execution of the program. However, in the examples in this book, it is important that the output shown at the end of the examples be as consistent as possible, so that this output can be verified with external tools. By providing a seed (an initialization value for the random number generator that will always produce the same sequence for a particular seed value) when creating the Random object, the same random numbers will be generated each time the program is executed, so the output is verifiable.1 To generate more varying output, feel free to remove the seed in the examples in the book. 
    选自《编程思想