Return True or False Randomly
The class java.util.Random already has this functionality: public boolean getRandomBoolean() { Random random = new Random(); return random.nextBoolean(); } However, it’s not efficient to always create a new Random instance each time you need a random boolean. Instead, create a attribute of type Random in your class that needs the random boolean, then use that … Read more