I can think of this way don't know if there is any inbuilt function for doing this or not
- So Make a function that will return random between two integers.
- make a variable probable having random value of 1-10
- Satisfy these condition
if(probable>=0 && probable<=5){
random = getUniqueRandom(0, 20);
}
else if(probable>=6 && probable<=9) {
random = getUniqueRandom(21, 80);
}
else if (probable == 10) {
random = getUniqueRandom(81, 100);
}
Here is the working implementation
import java.util.Random;
public class Solution {
private static Random r = new Random();
public static void main(String[] args) {
int pro1 = 0, pro2 =0, pro3 =0;
for(int i=0; i<10000; i++) {
int probable = getUniqueRandom(0, 10);
int random = 0;
if(probable>=0 && probable<=5){
random = getUniqueRandom(0, 20);
pro1++;
}
else if(probable>=6 && probable<=9) {
random = getUniqueRandom(21, 80);
pro2++;
}
else if (probable == 10) {
random = getUniqueRandom(81, 100);
pro3++;
}
//System.out.println(random);
}
System.out.println("Checked 10000 Times.\n0-20 Found: "+pro1);
System.out.println("21-80 Found: "+pro2);
System.out.println("81-100 Found: "+pro3);
}
static int getUniqueRandom(int min, int max){
int num = r.nextInt(max-min+1) + min;
return num;
}
}