java.util.Random.nextInt() Method


Advertisements


Description

The nextInt() method is used to get the next pseudorandom, uniformly distributed int value from this random number generator's sequence.

Declaration

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

public int nextInt()

Parameters

  • NA

Return Value

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

Exception

  • NA

Example

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

package com.tutorialspoint;

import java.util.*;

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

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

Next int value: 1228025286

java_util_random.htm

Advertisements