Get random boolean in Java

I recommend using Random.nextBoolean() That being said, Math.random() < 0.5 as you have used works too. Here’s the behavior on my machine: $ cat myProgram.java public class myProgram{ public static boolean getRandomBoolean() { return Math.random() < 0.5; //I tried another approaches here, still the same result } public static void main(String[] args) { System.out.println(getRandomBoolean()); } … Read more