setseed
随机类setSeed()方法 (Random Class setSeed() method)
setSeed() method is available in java.util package.
setSeed()方法在java.util包中可用。
setSeed() method is used to set the given seed of this Random Number Generator.
setSeed()方法用于设置此随机数生成器的给定种子。
setSeed() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
setSeed()方法是一个非静态方法,只能使用类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。
setSeed() method does not throw an exception at the time of set seed.
setSeed()方法在设置种子时不会引发异常。
Syntax:
句法:
public void setSeed(long ss);
Parameter(s):
参数:
long ss – represents the seed.
long ss –表示种子。
Return value:
返回值:
The return type of this method is void, it returns nothing.
此方法的返回类型为void ,不返回任何内容。
Example:
例:
// Java program to demonstrate the example
// of void setSeed(long ss) method of
// Random
import java.util.*;
public class SetSeedOfRandom {
public static void main(String args[]) {
// Instantiates Random object
Random ran = new Random();
// Display random value before seed
System.out.println("ran: " + ran.nextInt());
// By using setSeed(50) method is
// to set the seed value of this
// Random Value Generator by the given
// seed parameter
ran.setSeed(50);
// Display random value after seed
System.out.println("ran.setSeed(50): " + ran.nextInt());
}
}
Output
输出量
RUN 1:
ran: -983822763
ran.setSeed(50): -1160871061
RUN 2:
ran: -460404281
ran.setSeed(50): -1160871061
RUN 3:
ran: 316540002
ran.setSeed(50): -1160871061
翻译自: https://www.includehelp.com/java/random-setseed-method-with-example.aspx
setseed