Hi guys! I'm making a probability system. For example: If a player has specific permission, it has a 5% chance of obtain 1 more diamond when mining, but if it has other permission has a 10% chance of obtain 2 more diamonds when mining. I know the class Random, and Math.Random(), but with this I can't determine percentages.

Yes you can. If Math.random() returns a number in the range (0, 1) then there is a 10% chance that the number will be in the range (0, 0.1), no? Using that principle you can easily make conditions that are based certain percent probability.

(or if you want to go easy on yourself, just use ThreadLocalRandom with ThreadLocalRandom::nextInt(int) - also a bit faster, because ThreadLocalRandom doesn't require synchronization)

Think of 0 to 1 on a number line. The part from 0 to 0.1 (1/10) is 10% of the total area. Therefore, there is a 10% change the randomly generated number will land between those two numbers. If you can't extrapolate that process to other percents than there is not much help we can provide you.

Use Code (Text): Random r = new Random(); int chance =r.nextInt(100); if (chance <= playerChance) { //Run Code }

Code (Text): public static Boolean getRandomChance(double chance) { Random rand = new Random(); int random = rand.nextInt(100); if (random <= chance) { return true; } return false; }

Look up a "Weighted random". It is a simple algorithm for picking one option out of several with different chances.

That does absolutely nothing useful and is basically the same as one line of code (not to mention it makes an entirely new random for no clear reason, instead of using Math.random or much faster ThreadLocalRandom): if(r.nextDouble()<chance)

Maybe you're searching for something like this? https://www.spigotmc.org/threads/199285/#post-2073868

1. You should favour returning the primitive type 'boolean' over Boolean. 2. Use SplittableRandom or ThreadLocalRandom, they are both much faster alternatives than Random. 3. No need to create a new Random instance each time the method is run. 4. Spoonfeeding. People won't learn as much if you're just throwing code at them, especially if that code is inefficient or can be simplified: Math.random() <= chance

If you care about performance, use integers instead of floating points. RNGs work with integers so there's no pointless conversions and all that stuff.

You should've used a RangeMap instead of a List, which gives you O(log n) lookups instead of O(n) lookups. As for duplicate checking, use Sets for O(1) contains checks. Aside performance, it makes reasoning about results easier (since you're only dealing with natural numbers) @DizMizzer @MrBandit don't instantiate new Random objects every call, but create a private static final field instead (of course, this doesn't beat ThreadLocalRandom in performance, it's still overall the fastest Random implementation out there)

I did some experiments a while back and found that SplittableRandom was marginally faster. I guess I'll try it again because I see lots of people saying TLR is faster