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

Is it just me or has math.randomseed stopped working?

It was working fine a week ago but suddenly today I found it returning the same numbers again.

math.randomseed(os.time())

for i=1,10 do
	print(math.random(1,100))
end

I get the same sequence of numbers every time... Is it just me?

Thanks

2 comments

1

I kept getting the same sequence of numbers every second of time.

0

you will get pretty similar results with pretty similar keys

1 answer

✓ Accepted answer

Possibilities I can think of:

  • You are only looking at the first number, or when you looked at other numbers they just happened to be the same, or you only generated the results within the same second. Always use "math.random()" at least once (without using its value) to get rid of the first number, as it won't be random.
  • Maybe your system clock stopped working?
  • You're showing us a simplified version of your code (small differences in how you set the randomseed can make big differences! ex, multiplying os.time() by 1000, for some reason, seems to produce no difference between results for me, while (os.time() % 10000) * 1000 works fine)
  • I've seen some suggest that lua's random functions aren't very good

Ctrl+f for "math.randomseed" in http://lua-users.org/wiki/MathLibraryTutorial; it explains a bit on what's going on and offers a couple things you can do to improve the randomness.

3 comments

0

I'll try your third point... I've read the whole article on the wiki a while back so I'm not sure if that's the issue. If it persists then I'll just conclude that the problem lies in the reliability of the random generators in Lua/Roblox

0

Also I used tick() sometimes for the random seed and it doesn't seem to help much either

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