Java Random Boolean getBoolean()

Here you can find the source of getBoolean()

Description

get Boolean

License

Open Source License

Declaration

public static boolean getBoolean() 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Random;

public class Main {
    private static Random random;

    public static boolean getBoolean() {
        if (random == null)
            init();//from w  w  w  .j  a  v a2 s .  co m
        return random.nextBoolean();
    }

    public static boolean getBoolean(float chance) {
        if (random == null)
            init();
        return random.nextFloat() <= chance;
    }

    public static synchronized void init() {
        if (random == null)
            random = new Random();
    }
}

Related

  1. generateRandomBoolean()
  2. getBoolean()
  3. getBoolean()
  4. getBoolean()
  5. getBoolean(double probability)
  6. getBooleanWithProbability(int probabilityOfTrue)
  7. randBool(float chance)
  8. randomBoolean()