Math.randomseed question

is math.randomseed global? meaning if I set it in one server-script, will it apply to every other server-script and module on the server-side?

1 Like

math.randomseed() doesn’t exactly update globally across all scripts. So if you set math.randomseed() in one script, it will only affect the seed in that script only.

I would preferably use Random though.

1 Like

Hey Mike!

It actually does change the seed for all the scripts in your server!
Except scripts that are descendants of an actor since they use a different VM and hence a different seed.

Though math.randomseed() is not really used in most games you see. Since if another script decides to call math.random(), the seed changes and the pseudo-random seed is less reliable at that point.

If you are trying to use certain set seeds for how your game logic works, you should use the “Random” data type as @thom463s mentioned.

How do I make it so other modules aren’t affected by an math.randomseed established in a script?

You could use the Random data type

-- awesome random object that wont be effected by / effect other scripts!

local TerrainGeneration =
--> number provided can be a set seed, or left empty

local TerrainType = TerrainGeneration:NextInteger(0, 100)
--> This will provide you with a number that is not tied to the rest of the game

But you should go with math.random() if you don’t need to have a set-seed beforehand. Since it’s much simpler to use.