# Solved Prize Chances

Discussion in 'Spigot Plugin Development' started by Classified_Dev, Jun 1, 2017.

1. ### Classified_Dev

The plugin CratesReloaded has a chance system that you can have all the chances added up go above 100 for ex diamond could be 50/100, emerald 5/100, spawner 60/100 etc. I am wondering how to make a chance system like that, any help is appreciated.
(PS. Sorry for the very poorly worded post)

2. ### ScarabCoder Retired Resource Staff Retired

If you hardcode it, something simple like this should suffice:
Code (Text):
float random = new Random().nextFloat();
if(random <= 0.1){ //10% chance

}else if(random <= 0.3){ //20% chance

}

Otherwise, look up weighted randomness.

3. ### AKZOMBIE74

You could make a list of size 20 filled with 10 diamond, 1 emerald, and 12 spawners. Then use random to pick a value in that list.

EDIT: I know that math doesn't make sense, but neither does the scenario that was provided, mathematically speaking. For it to make sense he could use 3 lists of size 20. One filled with 10 diamond and 10 air, the second filled with 1 emerald and 19 air, the third with 12 spawners and 8 air. Then pick a random value for each one and check if the values for each one return air or whatever item was in that list. Then if in two lists an item was picked, value the one with a higher percentage than the other. For example if in the diamond list a diamond was picked and in the spawner list a spawner was picked, then pick spawner over diamond since spawner has 60% chance which is greater than diamond's 50% chance.

#3
Last edited: Jun 2, 2017
• Agree x 1