Where would you start making a RNG spawn?

The title says it all.

But lets say we have 3 types of, well lets say, zombies. Number 1 is common, Number 2 is rare, Number 3 is stupid rare.

But how would I make a simple rng table like that?

I’m not asking for full scripts, just a foundation or some block of code to help me get started.

I belive this tutorial wud b helpful. If not, dm me here abt ur enquiries.

1 Like

This worked, thank you so much!

local chances = {100, 50, 2}

-- add all the chances up into a total value this will be 152 in this example 
local total = 0
for i, value in ipairs(chances) do total += value end

-- we pick a random number between 0 and 152
-- then we loop each chance value and deduct it from the random value
-- once the random value goes below or equal to 0 that is the item that was selected
local function GetRandom()
	local randomValue = math.random() * total
	for i, value in ipairs(chances) do
		randomValue -= value
		if randomValue <= 0 then return i end
	end
end

-- 1 has a 65.7% chance (100 / 152 * 100 = 65.78947368421053)
-- 2 has a 32.8% chance (50 / 152 * 100 = 32.89473684210526)
-- 3 has a 1.3% chance (2 / 152 * 100 = 1.315789473684211)

print(GetRandom())
print(GetRandom())
print(GetRandom())
print(GetRandom())
print(GetRandom())