mardi 3 août 2021

How to increase propability of a certain number for random() in Java?

First of all, the method I am currently using for picking up a random number within a range of 1-45 is:

public int getRandomNumber(int min, int max) {
    return (int) ((Math.random() * (max - min)) + min);
}

What I want to do is, suppose that there are six numbers in an array of int

int[] numbers = [2, 4, 6, 8, 10, 12];

and I want to increase the probability (about 20% to 30%) for picking that numbers in the array from a randomly generated number in a range of 1 ~ 45.

Is there any way to solve this problem?

Thanks.




Aucun commentaire:

Enregistrer un commentaire