RANDOM NO GENERATOR

import java.util.*;
public class RandomNoGenerator {
public static void main(String[] args) {
//way to generate any random no between 0 and 1
double no = Math.random();
System.out.println("random no in double format " + no);
// Way to generate any random no
Random no2 = new Random();
int n = no2.nextInt();
System.out.println("2nd random no is " + n);
//correct way to generate random no between two no here 5 and 10 are two no
int rn = 5 + (int) (Math.random() * (10 - 5) + 1);
System.out.println("random no between 5 and 10 is " + rn);
}
}

No comments:

Post a Comment