Java – Create Random Boolean Value

To create a random integer value in Java, use Random.nextInt() method. Create java.util.Random class object and call nextInt() method on this object. nextInt() returns a randomly generated integer value.

In the following example, we will create a random integer value using nextInt() method.

Java Program

</>
Copy
import java.util.Random;

public class Example{ 
    public static void main(String[] args) {
    	Random random = new Random();
    	int i = random.nextInt();
    	System.out.println("Next random integer value is : " + i);
    }
}

Output

Next random integer value is : 759359738

Reference to Random.nextInt() method for syntax and more example programs.

Conclusion

In this Java Tutorial, we learned how to create a random integer value using java.util.Random.nextInt() method.