lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I've done a bit of digging, and I believe it may have to do with the
precision of your seed.  Take the following example:

local values = {}
for i=1,1e1 do
 math.randomseed(i)
 values[math.random(100)] = true
end
print(#values)

Some results:
1e1: 1 unique result
1e2: 2 unique results
1e3: 11 unique results
1e4: 100 unique results

I suspect that has implications overall, when trying to seed the PNG
in successive atempts, since in my experience consecutive values yield
the same result, up until some point.  Thats the best I can offer with
my limited resources at the moment.

I should probably actually active my entire brain before I send off an
email.  My example doesn't illustrate very much, given the fact that
the math.random(100) is actually causing the issue here.  The initial
random number given a seed grows, and is given as a number between 0
and 1, as can be seen here:

new value 0.0012512588885159 at 1
new value 0.0013733329264199 at 2
new value 0.0014648884548479 at 3
new value 0.0015564439832759 at 4
new value 0.0016479995117038 at 5
new value 0.0017700735496078 at 6
new value 0.0018616290780358 at 7
new value 0.0019531846064638 at 8
new value 0.0020752586443678 at 9

By asking for a random number between 0 and 100, you're killing the
precision of the generator, which causes the issue you're
experiencing, giving you the same number for consecutive seed values.