java.util.Random.setSeed() Method

Advertisements


Description

The setSeed(long seed) method is used to set the seed of this random number generator using a single long seed.

Declaration

Following is the declaration for java.util.Random.setSeed() method.

public void setSeed(long seed)

Parameters

  • seed--This is the initial seed.

Return Value

NA

Exception

  • NA

Example

The following example shows the usage of java.util.Random.setSeed()

package com.tutorialspoint;

import java.util.*;

public class RandomDemo {
   public static void main( String args[] ){
      // create random object
      Random randomno = new Random();
      
      // setting seed
      randomno.setSeed(20);
      
      // value after setting seed
      System.out.println("Object after seed: " + randomno.nextInt());
   }    
}

Let us compile and run the above program, this will produce the following result.

Object after seed: -1150867590



Advertisements
Advertisements