I need a function which generates me random numbers but where some numbers can appear more often then others.
Lets say i want random numbers from 1 to 10 where 2 and 3 have twice the chance to appear than the rest.
How can i do this in java? Haven`t found a function for this.
Edit: Code i have so far (Which was a compromise solution, i know it`s not what i want)
int min;
int max;
double min1;
double max1;
for(int j=0;j<Ammount_numbers;j++) {
if(min1==0) {
min1= min + (Math.random() * (max+1-min));
max1= min + (Math.random() * (max+1-min));
}
double randomnumber = min1 + (Math.random() * ((max1-min1) + 1));
}
Min and Max are the borders (1 to 10 in the example) And with min1 and max1 i generated new, smaller borders so that the randomnumber is clustered in a random range.. And as i said: i know that this is not what i wanted, it was just a compromise solution so i could work with it..