#Random/rng system

1 messages · Page 1 of 1 (latest)

regal topaz
#

What is the best way to make random/rng like slime rng

silver cargo
#

weighted tables

regal topaz
silver cargo
regal topaz
long pawn
#

yeah

#

Weighted systems are best for this

covert nimbus
#
local rarityTable = {
  {Rarity = "Epic", Chance = 1/25},
  {Rarity = "Rare", Chance = 1/5},
  {Rarity = "Uncommon", Chance = 1/2},
  {Rarity = "Common", Chance = 1}
}

local luck = 175 -- Calculated as a procentage

local function roll()
  local rng = math.random()
  print("RNG Before Luck:", rng)

  rng = rng / (1 + luck / 100)
  print("RNG After Luck:", rng)
  
  for _, rarity in rarityTable do
    if rarity.Chance >= rng then
      print("Obtained:", rarity.Rarity)
      print("Chance: 1 in " .. 1 / rarity.Chance)
      break
    end
  end
end

roll()``` Here's something I wrote up
#

just don't go negative and you should be good