Minecraft – How does minecraft:uniform work (loot tables in Minecraft)

minecraft-java-edition

I was wondering how minecraft:uniform works; how can it select a random number between min and max while both of those being included?

Example: blaze.json has a min of 0 and a max of 1. My guess is that minecraft:uniform picks a random float in between these numbers and rounds it to the nearest integer. Is this correct? If so, can I set the maximum value to, say, 1.5 so that I have more chances of getting 1 blaze rod?

My problem with this approach is that for example if you have min 0 and max 2, then there is actually 50% chance of receiving 1, and 25% of receiving 0 or 2. It's not evenly distributed for endpoints.

Best Answer

Not sure if you are still looking for an answer but just stumbled across your question.

That is not actually how it works. As I understand it, the function will evenly distribute between each integer in the range of floats and use the modulus (remainder) for a percentage chance of an additional drop.

This works similarly to the experience given when smelting items for example. If the item has a 1.5 xp on smelt there is a guarantee to get 1 xp and a 50% chance of getting 1 additional xp when processed. If I understand correctly (I don't have a chance to test it right now) Then if you set the uniform distribution to 0.0 to 1.5 it would be evenly distributed across that range. So as an example, if you had it set at 0.0 to 1.5, you still have an 50/50 chance of 0 or 1 blaze rod, but you have a 50% chance of a second rod to drop if the first one dropped. It would just grab a random float from 0.0 to 1.5. If it is 0.0 to 0.49 no drop, if it's 0.50 to 1.0 one rod drops, and if it's 1.01 to 1.5 it would drop two rods. But the distribution would still be uniform across that range.

I could be mistaken on this point and it will require some testing to be sure but that is how I have understood the process. I am including a link to a document that has a little information on the different randoms available in loot tables. Hope this helps.

https://gist.github.com/misode/66456e57372ce62cd9b65d1052521069#random-integers

Cheers!

UPDATE:

I was wrong. The decimal does absolutely nothing in regards to the count of items dropped unlike the xp drops. Tested it out with a few hundred bats with a 0.0 to 1.99 table and each time it comes out nearly perfectly 50/50.