Hey! Im currently making a game, Cannot give too much info but the game itself, But it selects other minigames (like epic minigames) and then executes them, I wanted to make a random system with probabilities, so some games are more rare than others and i wanted to know. What is the best way to do this without needing to update the Raritie/Weight of each game to add a new one?
1 Like
Adding a new game will have to change the probabilities of at least one other game. Do you mean something more specific? Like “Rare” games all always have the same probability and so on?
Not like that, Something like all the normal mini-games have the same probability, But idk, a easter egg or very rare game has one in 100,000 chances to appear
you could do a weighted random selection like this:
local games = {
a = 0.1, -- number is proportional to its probability of being chosen
b = 0.2,
c = 0.3,
d = 0.4
}
local TOTAL_CHANCE = 0
for g, c in pairs(games) do
TOTAL_CHANCE += c
end
local RNG = Random.new()
local function getRandomGame()
local counter = 0
local rNum = RNG:NextNumber(0, TOTAL_CHANCE)
for g, c in pairs(games) do
counter += c
if counter > rNum then
return g
end
end
end
print(getRandomGame())
1 Like
This will work but you don’t need the shuffle function.
1 Like