Skip to main content

Posts

Showing posts with the label Getting random numbers in Java [duplicate]

Getting random numbers in Java [duplicate]

 Getting random numbers in Java [duplicate] Do Check My Video On generating Random number in java  Example: import java.util.Random; class Test{ public static void main(String[] args){ Random random = new Random(); int y = random.nextInt(); System.out.println(y);//any random value between Integer.MAX_Value to Integer.MIN_Value int x = random.nextInt(6); System.out.println(x);////it will give any random value in between 0 to 5 double d = random.nextDouble();//random value in 0 to 1 System.out.println(d); boolean b = random.nextBoolean();//gives true or false System.out.println(b); } }