No need to get defensive, more than just you read these bug reports and there was enough conjecture here (as well as in other places) that I wanted to post about not seeding multiple times… just to be sure. I don’t know you, I couldn’t tell your level of expertise.
I, also, recently ran into the random bug you point out (it is indeed a bug) and it was very simple to reproduce.
So, devs, here you go: main.lua ::
[code]
– without seeding, you get a different sequence and different starting number every run
print(“No Seed Set”);
for i = 1, 10 do
print(math.random(1, 100));
end;
[code]
– as soon as you seed, you get the same starting number
_seed = os.time();
print("Seed: "…_seed);
math.randomseed(_seed);
for i = 1, 10 do
print(math.random(1, 100));
end;
[code]
– and again to demonstrate the same problem each re-seed
_seed = _seed + 1;
print("Seed: "…_seed);
math.randomseed(_seed);
for i = 1, 10 do
print(math.random(1, 100));
end;
-- finally, the workaround
\_seed = \_seed + 1;
print("Seed: "..\_seed);
math.randomseed(\_seed);
math.random(); -- \<\<\<\<\< this is the work around...ick.
for i = 1, 10 do
print(math.random(1, 100));
end;
If you seed, this shows the first number in each sequence to be the same.
Specifically, if you re-seed you again get the same number for the first in the sequence.
And the last run shows the workaround.
I did some further testing and found some odd things:
- Over a period of about 10 minutes, the first number went from 25 to 26 to 27. I was not able to reproduce what this coincided with.
- It appears to only be related to actually calling math.randomseed and then running through a sequence. When I do not seed, I get a different sequence (and first number) ever time I run the test. So it appears this bug is directly in connection with performing a seed.
I completely agree with menace960 – while there is a workaround, this is definitely a bug and one that comes up each time you seed. This should definitely be flagged as a priority bug since anyone using randomseed will get bitten.
Scott
[import]uid: 5659 topic_id: 358 reply_id: 1439[/import]