Get Random boolean in Java

Description

The following code shows how to get Random boolean.

Example


//from  www  . jav a 2 s. c  o m
import java.util.Random;

public class Main {
  public static void main(String[] argv) throws Exception {

    Random rand = new Random();

    boolean b = rand.nextBoolean();
    System.out.println(b);
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Development »




Java Algorithms
Java Clipboard
Java Compiler
Java Desktop
Java Virtual Machine
Java Math
OS
Random
Java Robot
Java RuntimeMXBean
Java Timer
Java UUID
Java Internationalization