Just got a client on a massive job, who is now not too happy that my script doesn’t work the way he wants, and I looked, and the randomseed function is doing nothing at all, proof:
Just got a client on a massive job, who is now not too happy that my script doesn’t work the way he wants, and I looked, and the randomseed function is doing nothing at all, proof:
:o windows xp
I get the same when setting the randomseed. Try to not use math.randomseed and see what the results are.
See Why is the first random number after randomseed() not random?
Basically you should only be calling [tt]math.randomseed[/tt] once.
Roblox calls math.randomseed(tick()) when scripts execute anyway so it isn’t needed.
I do only call it once, and if roblox does seed random, why am I always getting the same numbers from math.random? did you even look at my post? I have a good grasp of how to use randomseed, and it has worked in the past exactly has documented, now, it does absolutely nothing, it’s broken, if you don’t believe me, test it for yourself, and there is no problem with calling randomseed more than once, some programs do it intentionally, because they want specific numbers, or repeatability in testing, or the ability to reload a generated map, where the save is only the seed number
Edit: it appears randomseed breaks the random number generator, as calling it at all will always seed to the exact same numbers
Edit: I see now, randomseed does some sort of cacheing thing, where the first random number is a static number regardless of seed, thanks, guys, but seriously, this used to work like 4 years ago >.<
You sure about that? Because my randoms are almost always consistent, and I have to add math.randomseed(tick()) at the beginning of my scripts to fix it.
Well, for my game at least, the random numbers aren’t the same unless I call randomseed (which I do as a good habit, which breaks everything now, so… yeah)
removed all randomseed calls, and I have good results now
I have this issue. Everytime you set randomseed the first call to math.random is the same, but after that it changes.
You sure about that? Because my randoms are almost always consistent, and I have to add math.randomseed(tick()) at the beginning of my scripts to fix it.[/quote]
I’m pretty sure. I’ve never ever had to call math.randomseed().
You guys seem to fail to understand what randomseed does and how the random function works. I’ll try to simplify it though. The random function does NOT produce random numbers. It produces PSEUDORANDOM numbers. These pseudorandom numbers are based off the seed you give to the random function, via the randomseed function. If you give it the same seed it will produce the SAME pseudorandom numbers as it is basing them off of the SAME seed.
TL;DR every DIFFERENT number you give to randomseed will produce a DIFFERENT chain of “random” numbers from the random function.
EDIT: I forgot to mention since every chain is related to the seed if you give similar seeds then the chains will be similar. You should refrain from seeding so often. (IE what Seranok said)
Erm. I think everyone here understands that already, what you didn’t realize, is that the first number produced by random after seeding is cached somehow, and isn’t ‘random’, in fact, it’s always the same
Just so you know, please don’t underestimate people here, it’s a bad flaw, most of us are years into programming, and Lua is our native languages, I was dealing with randomseed ~5 years ago, though your avatar pic is quite cute, so I can forgive you :]
My question is, how did you read all the posts and come to the conclusion none of us understood how random works?
[quote] Erm. I think everyone here understands that already, what you didn’t realize, is that the first number produced by random after seeding is cached somehow, and isn’t ‘random’, in fact, it’s always the same
Just so you know, please don’t underestimate people here, it’s a bad flaw, most of us are years into programming, and Lua is our native languages, I was dealing with randomseed ~5 years ago, though your avatar pic is quite cute, so I can forgive you :]
My question is, how did you read all the posts and come to the conclusion none of us understood how random works? [/quote]
Sorry if I came off as hostile, I was in a bit of a bad mood
Anyways this isn’t a bug, this is how the lua random works. The way you are using tick() is giving randomseed() consecutive numbers. So lets simplify that to a for loop (for demonstration purposes).
We get this.
Similar to the problem you had. They are all the same number. However if we remove the rounding we get this.
They all all different, just very very slightly. When rounded they become the same number.
What about the second number generated by random? They are also related.
They look more random however you will notice a pattern similar to
0.2
0.5
0.8
0.2
0.5
0.8
over and over again.
As you can see it isn’t cached its just very very similar. I hope that explains what I was trying to say in a less hostile way
I repeated my test with floats, and they are the same number, however, all mine ran at the start of the thread/when no other random numbers have been generated, and the seed pool is fresh, if you notice in yours, you are running off of an already filled pool, so the cache, which is based off of the current seed pool(I assume), is different, however, if you do what I did, and run it off of a new seed pool, like in the start of the game, the cached number is always exactly the same
if you didn’t know, the random number generation works off of a pool of data as well, and random seed is only the method that decides how this pool is interpreted, and when you call random, you change the pool around, this is why random generates different numbers all the time, and not the same, even though it’s an algorithm
I just tried it on fresh threads both on my computer and on a roblox server and got different (but very similar) numbers. Anyways this isn’t really relevant anymore since you managed to fix your problem. Good luck with future development.