# How would you calculate the probability of something without replacement?

Using the classic Marbles In A Bag example, given a table like this and a set amount of selections, how would you calculate the expected chance of something occurring without replacement? I am trying to calculate the percentage chance of the player being a starter zombie in a zombie game, so that the player can see their chance of being a zombie because it is not a static chance each round.

``````local SelectionsAmount = 2
local Marbles= {
["Red"] = 4,
["Blue"] = 5,
}
``````

A model of what I am trying to calculate:

I have solved my own problem, if anyone needs the script here you go. I used placeholder variables for it, but you can change around the numbers in it if you need

``````--Placeholders
local Exit = {
["Bob"] = 2,
["James"] = 2,
["Hunter"] = 5
}
local ZombieAmount = 1
local ChanceOfZombie = 0
local LocalName = "Hunter"

--Function, do not edit
local ChancesTable = {}
local StartTick = tick()
local function recursion(CurrentTable,HypotheticalZAmount,PrevChance)
if HypotheticalZAmount < ZombieAmount then
local TotalAmount = 0
for PlrName,Amount in pairs(CurrentTable) do
TotalAmount += Amount
end
for Selection,Num in pairs(CurrentTable) do
local ChanceOfSelection = Num/TotalAmount
if Selection == LocalName then
ChanceOfZombie += (Exit[LocalName]/TotalAmount)*PrevChance
else
local NewTable = {}
for PlrName,Amount in pairs(CurrentTable) do
if PlrName ~= Selection then
NewTable[PlrName] = Amount
end
end
recursion(NewTable,HypotheticalZAmount+1,ChanceOfSelection)
end
end
end
end

recursion(Exit,0,1)
print(ChanceOfZombie) --This print statement returns the decimal
print(math.floor((ChanceOfZombie*100)+0.5).."%") --This print statement returns String version, useful for UIS
``````