Answers on a previous question told me to put math.randomseed(tick()) told me to put that line of code at the very top of my script. My question is do I need it in a function or can I put it at Line One?
math.randomseed(tick())-- does it have to be here local Maps = game.ServerStorage:WaitForChild("Maps"):GetChildren() function chooseMap() --math.randomseed(tick()) or can it/ does it have to be here local randomMap = Maps[math.random(1, #Maps)]:Clone() print(randomMap.Name) end
what if i had a while true do loop like this :
--does math.randomseed(tick()) have to be on the first line -- code in between and naming functions and stuff before the loop, etc. while true do function chooseMap() -- or can it be in the function end
basically, my question is where can it go
Line 1. You should only ever execute randomseed
once, at the very start of the game.
Putting it in a function would mean you could accidentally invoke it again.
The first several numbers you get after setting a seed typically aren't very high quality.
You should ask for a few numbers that you'll just throw away to prime it:
math.randomseed(tick()) for i = 1, 10 do math.random() end
Alternatively, you can use a more "chaotic" seed like
math.randomseed(tick() % 1 * 1e6)
You put it inside the function
local Maps = game.ServerStorage:WaitForChild("Maps"):GetChildren() function chooseMap() math.randomseed(tick()) --< RIGHT HERE local randomMap = Maps[math.random(1, #Maps)]:Clone() print(randomMap.Name) end
Marked as Duplicate by hiimgoodpack, lukeb50, Void_Frost, and Goulstem
This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.
Why was this question closed?