java.util.Random.nextBoolean() Method

Advertisements


Description

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

Declaration

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

public boolean nextBoolean()

Parameters

  • NA

Return Value

The method call returns the next pseudorandom, uniformly distributed boolean value.

Exception

  • NA

Example

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

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 boolean value 
      boolean value = randomno.nextBoolean();
      
      // 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: true



Advertisements
Advertisements