# 1.15.2 How to make chances

Discussion in 'Spigot Plugin Development' started by Hortexel, Apr 2, 2020.

1. ### Hortexel

Hi, i have a problem
I'm trying to write a plug with a 0.001 chance of a diamond falling out
I would like to ask if the plugin that I wrote is good, because unfortunately I do not fully understand Java
Code (Java):
double randDouble = Math.random();
e.setDropItems(false);
if(randDouble <= 0.3D) p.sendMessage(String.valueOf(randDouble*100));
if(randDouble <= 0.001D) {
p.sendMessage(ChatColor.RED+"Elo: diament");
} else if(randDouble <= 0.02D) {
p.sendMessage("Elo: zelazo");
} else if(randDouble <= 0.003D) {
p.sendMessage("Elo: zelazo");
}

2. ### joshuacc

Code (Text):
Random rand = new Random();
int whole = rand.nextInt(100);
int d = rand.nextInt(100);
double dec = 0.01 * d;
double fi = whole + dec;
if(fi < 0.01D)
//Insert function here
Should be good randomizer for a range of 100 - 0.01

3. ### Hortexel

And such a solution?
Code (Java):
Random random = new Random();
double chance = random.nextDouble();
p.sendMessage(String.valueOf(chance));
if(chance <= 0.001){
p.sendMessage(ChatColor.RED+"DIAMENT");
}

4. ### joshuacc

Code (Text):
double max = 100;
double min = 0.001;
double range = Math.abs(max - min);
double fi = (Math.random() * range) + (min <= max ? min : max);
if(fi < 0.001)
//Do the thing
Just saw how better Math.random is to use so here's a better one