Example1
import java.lang.Math;   
public class RandomNumberExample1  
{   
public static void main(String args[])   
{   
// Generating random numbers  
System.out.println("1st Random Number: " + Math.random());   
System.out.println("2nd Random Number: " + Math.random());  
System.out.println("3rd Random Number: " + Math.random());   
System.out.println("4th Random Number: " + Math.random());   
}   
}  



Example2
public class RandomNumberExample2  
{  
public static void main( String args[] )   
{  
int min = 200;  
int max = 400;  
//Generate random double value from 200 to 400   
System.out.println("Random value of type double between "+min+" to "+max+ ":");  
double a = Math.random()*(max-min+1)+min;   
System.out.println(a);  
//Generate random int value from 200 to 400   
System.out.println("Random value of type int between "+min+" to "+max+ ":");  
int b = (int)(Math.random()*(max-min+1)+min);  
System.out.println(b);  
}  
}  



Exmple3
import java.util.Random;   
public class RandomNumberExample3  
{   
public static void main(String args[])   
{   
// creating an object of Random class   
Random random = new Random();   
// Generates random integers 0 to 49  
int x = random.nextInt(50);   
// Generates random integers 0 to 999  
int y = random.nextInt(1000);   
// Prints random integer values  
System.out.println("Randomly Generated Integers Values");  
System.out.println(x);   
System.out.println(y);   
// Generates Random doubles values  
double a = random.nextDouble();   
double b = random.nextDouble();   
// Prints random double values  
System.out.println("Randomly Generated Double Values");  
System.out.println(a);   
System.out.println(b);    
// Generates Random float values  
float f=random.nextFloat();  
float i=random.nextFloat();  
// Prints random float values  
System.out.println("Randomly Generated Float Values");  
System.out.println(f);   
System.out.println(i);   
// Generates Random Long values  
long p = random.nextLong();   
long q = random.nextLong();   
// Prints random long values  
System.out.println("Randomly Generated Long Values");  
System.out.println(p);   
System.out.println(q);    
// Generates Random boolean values  
boolean m=random.nextBoolean();  
boolean n=random.nextBoolean();  
// Prints random boolean values  
System.out.println("Randomly Generated Boolean Values");  
System.out.println(m);   
System.out.println(n);   
}   
}  



Example4
import java.util.concurrent.ThreadLocalRandom;   
public class RandomNumberExample4  
{   
public static void main(String args[])   
{   
// Generate random integers between 0 to 999   
int a = ThreadLocalRandom.current().nextInt();   
int b = ThreadLocalRandom.current().nextInt();   
// Print random integer values  
System.out.println("Randomly Generated Integer Values:");  
System.out.println(a);   
System.out.println(b);   
// Generate Random double values  
double c = ThreadLocalRandom.current().nextDouble();   
double d = ThreadLocalRandom.current().nextDouble();   
// Print random doubles   
System.out.println("Randomly Generated Double Values:");  
System.out.println(c);   
System.out.println(d);   
// Generate random boolean values  
boolean e = ThreadLocalRandom.current().nextBoolean();   
boolean f = ThreadLocalRandom.current().nextBoolean();   
// Print random Booleans   
System.out.println("Randomly Generated Boolean Values:");  
System.out.println(e);   
System.out.println(f);   
}   
}  


Example5
import java.util.Random;   
public class RandomNumberExample5   
{   
public static void main(String[] args)   
{   
randomInts(5);  
randomInts(9, 50, 90);  
//getStreamOfRandomInts(30, 50);  
}   
//method that generates a stream of integers having size 5  
public static void randomInts(int num)   
{  
Random random = new Random();  
random.ints(num).forEach(System.out::println);  
}  
//method that generates a stream of 9 integers between 50 to 90  
public static void randomInts(int num, int origin, int bound)   
{  
Random random1 = new Random();  
random1.ints(num, origin, bound).forEach(System.out::println);  
}  
} 
