Randomize Numbers

MODULE SCRIPT:

local module = {}

module.ThriveChance = math.random(1, 2)
module.StayChance = math.random(1, 2)

return module

I want to make ThriveChance and StayChance random.
Of course using math.random will make it choose between 1 or 2, but what it ever chooses will stay like that forever.

For example, if ThriveChance is equal to 1, then that’s totally fine IF I call it one time throughout the game, but if I call it multiple times, it will still be equal to 1, because thats what it chose at the start of the game.

Hopefully that made sense, and someone has a way to combat this.
Any help is appreciated!

Create a function and call it whenever you want to generate a random number:

local module = {}

function module.GetRandom(): number
    return math.random(1, 2)
end

for index = 1, 10 do
    print(module.GetRandom())
end
1 Like

Wow, that worked great! Thank you!!

I made a little tweak to it though,

module.ThriveChance = function(): number
	local Chance = math.random(1, 2)
	return Chance
end

Just so it takes up less space.
(still works the same!)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.