Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

What does random seed and tick do?

I viewed a tutorial and seen some roblox dev forum but I just dont understand what does randomseed and tick do. Please give me a brief explanation thank you.

1 answer

I am not that great at explaining, but I will do my best.

Tick You've probably already heard over a million times that tick gives you the time in seconds that has passed since January 1st, 1970. But what is it useful for? Let's say you want to set a timer. You want to wait 10 seconds until a bomb gets destroyed.

local bomb = game.Players.LocalPlayer.Backpack.Bomb
local start = tick()
local timer = tick() - 10

if bomb then 
	if tick() == start - timer then -- 10 seconds in
		bomb:Destroy()
	end
end)

The date January 1st, 1970 does not really matter if you use tick that way.

Randomseed There's very little difference between math.random and math.randomseed. Math.randomseed is used to set a new seed of random numbers. It does not need two parameters. You probably already know that there's no way you can ever get random numbers from Lua. I guess math.randomseed is a bit more random, but here's why. (Pretend part of the code blocks are output)

Math.random

print(math.random(1,2))
print(math.random(1,2))
print(math.random(1,2))
--------------------------------
-- Output:
1
1
1
-- Now let's say I ran the game again. Output:
1
1
1

Math.randomseed

math.randomseed(1)
print(math.random())
print(math.random())
print(math.random())
------------------------------------
-- Output:
0.1
0.2
0.3
-- Now let's say I ran the game again. Output:
0.1
0.2
0.3
-- I know, not very random numbers but I'm just doing it so you can notice the difference in the outputs for math.random and math.randomseed

Notice how math.random printed out the same number every single time. Math.randomseed printed out different numbers, but it wasn't exactly random because look at when we try to run the game again. It doesn't print the same numbers each time we wanted it to print, but it does print the same sequence as last time.

I thought maybe it would be helpful to you if I told you how games such as Epic Minigames chooses maps pretty randomly. I read that developers use math.randomseed along with tick because I guess tick changes up the sequence since the tick (time) can vary.

I'm sorry that I could not provide a brief explanation just like you asked. These are harder concepts to explain and understand. But if you did read all this, I hope it was helpful to you. If you still do not understand, I have some links which were helpful in letting me cultivate my answer. Here's the link for tick. And here's the link for randomseed

I will be editing my answer if I find more information about this.

This discussion is preserved as it was. New answers, comments, and votes are closed.