setseed_Java Random setSeed()方法与示例

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

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值