Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 7 years ago

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

1
I kept getting the same sequence of numbers every second of time. KingLoneCat 2642 — 7y
0
you will get pretty similar results with pretty similar keys connor12260311 383 — 7y

1 answer

Log in to vote
1
Answered by 7 years ago

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.

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 iiFlamingIcicle 45 — 7y
0
Also I used tick() sometimes for the random seed and it doesn't seem to help much either iiFlamingIcicle 45 — 7y
Ad

Answer this question