Question "Weights"?

Discussion in 'Bukkit Help' started by Dark_Serpent, Aug 6, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    Dark_Serpent

    Hopefully I'm posting in the right sub forum, but I have a bit of a question.

    A lot of plugins mention "weight" values for random generation, for instance, random generation of items in chests. Is this a staple coding term? And if it is, can someone explain to me in more detail what it means?

    i.e. If an item has a weight of 5 and another one has a weight of 1, which one is more likely to spawn, and also, what are the general percentages? Is it based on an additive total or is it default for every single number?
     
  2. Offline

    Rayzr522

    Well hello again!
    So basically weights are how often XYZ item will be chosen, so the higher the weight the more often it will be chosen.

    Usually how this works in code is you generate a random number from 0 to the total weight of all objects and then see which one is selected:
    Explanation.png
    I hope that explains it better.

    Happy coding!
     
Thread Status:
Not open for further replies.

Share This Page