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?
1 | math.randomseed(tick()) -- does it have to be here |
2 | local Maps = game.ServerStorage:WaitForChild( "Maps" ):GetChildren() |
3 |
4 | function chooseMap() |
5 | --math.randomseed(tick()) or can it/ does it have to be here |
6 | local randomMap = Maps [ math.random( 1 , #Maps) ] :Clone() |
7 | print (randomMap.Name) |
8 | end |
what if i had a while true do loop like this :
1 | --does math.randomseed(tick()) have to be on the first line |
2 | -- code in between and naming functions and stuff before the loop, etc. |
3 | while true do |
4 | function chooseMap() -- or can it be in the function |
5 | 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:
1 | math.randomseed(tick()) |
2 | for i = 1 , 10 do |
3 | math.random() |
4 | end |
Alternatively, you can use a more "chaotic" seed like
1 | math.randomseed(tick() % 1 * 1 e 6 ) |
You put it inside the function
1 | local Maps = game.ServerStorage:WaitForChild( "Maps" ):GetChildren() |
2 | function chooseMap() |
3 | math.randomseed(tick()) --< RIGHT HERE |
4 | local randomMap = Maps [ math.random( 1 , #Maps) ] :Clone() |
5 | print (randomMap.Name) |
6 | 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?