As an alternative i believe you could use this function to get three (given amount) outcomes, as well:
( other options/recommendations in this topic should work)
function GetOutComes(NumberOfOutcomes, Choices) ----Amount, Table of Choices
local ChosenValues = {}
for i = 1, NumberOfOutcomes do
local value = Choices[math.random(1, #Choices)]
while table.find(ChosenValues, value) do --If we can find the random value then get another random value, if we cant end the loop and add it to the used table
value = Choices[math.random(1, #Choices)]
end
table.insert(ChosenValues, value)
end
return Outcomes
end
For what I’ve seen in your code, I think you are trying to get three random outcomes from an array, without repeating. You used an array to store choices that are already picked. You should delete the choice from the choice array
Here’s the code for what you are trying to do (if I understood you correctly)
function getOutcomes(choices, outcomes)
local gotOutcomes = {}
for i = 1, #outcomes do
local pickedNum = math.random(1, #choices)
table.insert(gotOutcomes, choices[pickedNum])
table.remove(choices, pickedNum)
end
return gotOutcomes
end