#RNG help

1 messages · Page 1 of 1 (latest)

pulsar jungle
#

Hi I need help with a better rng system

#

So the current script is just

local Num = math.random(1,100)
if Num <=70 then
print("Common")
elseif Num <=90 then
print("Uncommon")
else
print("legendary")
end

#

I want it to be more flexible and easier to configure so I can add 3% or even 0.1% and more

#

This is how it is working, it works pretty well but hard to calculate the chances when I want something new

marble slate
#

I would simply have a table as such:

local rarities = {
  {name = "Common", chance = 70},
  {name = "Uncommon", ...}
  ...
}
``` or how ever many rarities you have then loop through your rarities, if Num is larger than the rarity.chance then thats the one to spawn
#

while checking down the list however, make sure to have a cumulative of the previous chances so that the chance(numbers larger than "Num") gets smaller, aka more rare, by using a cumulative variable or smt