java.util.Random.next() Method


Advertisements


Description

The next(int bits) method is used to generate the next pseudorandom number.

Declaration

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

protected int next(int bits)

Parameters

  • bits -- This is the random bits.

Return Value

The method call returns the next pseudorandom value from this random number generator's sequence.

Exception

  • NA

Example

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

package com.tutorialspoint;

import java.util.*;

public class RandomDemo {
   public static void main( String args[] ){
   // create random object
   Random randomno = new Random();
      
   // get next next pseudorandom value 
   int value = randomno.nextInt();
      
   // check the value  
   System.out.println("Value is: " + value);
   }  
}

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

Value is: -187902182

java_util_random.htm

Advertisements