

Ok, so I have code that looks like this at the top of the program:
math.randomseed( os.time() )
Then I have this code in the event loop every time I tap a button:
screen.moveto( 0, 52 )
print( math.random( 10 ) )
However, the sequence of numbers ( 1, 7, 8, etc. etc. ) is the same every
time. Am I doing something wrong or stupid? Is this supposed to work and
is just a quirk or bug?
Oh yeah, Plua 2.0b7, Palm Lifedrive ( OS v5.4.8 )
[Nontext portions of this message have been removed]


math.randomseed( os.time() )
print( math.random( 10 ) )
print( math.random( 10 ) )
print( math.random( 10 ) )
print( math.random( 10 ) )
print( math.random( 10 ) )
gui.event()
Gives me 9,3,3,4,8 on one launch, 7,2,4,10,8 on another, etc. Seems to
work for me. I'm running in the Palm OS Simulator, though.


Hi,
> math.randomseed( os.time() )
>
> Then I have this code in the event loop every time I tap a button:
>
> screen.moveto( 0, 52 )
> print( math.random( 10 ) )
>
> However, the sequence of numbers ( 1, 7, 8, etc. etc. ) is the same
every
> time. Am I doing something wrong or stupid? Is this supposed to
work and
> is just a quirk or bug?
>
> Oh yeah, Plua 2.0b7, Palm Lifedrive ( OS v5.4.8 )
It is a bug. math.randomseed() does not accept large numbers. For now,
try a smaller seed.
Regards,
Marcio.


Also, math.randomseed(0) doesn't work usefullyit seems to ignore a seed of 0.
E.g. This program:
math.randomseed(10)
math.randomseed(0)
print(math.random(10),math.random(10),math.random(10))
Just produces 4 4 3 everytime it is run...
So, we need to do a math.mod(systime, x).
What is the value of x  i.e. What is the largest number that randomseed can manage?
>It is a bug. math.randomseed() does not accept large numbers. For now,
>try a smaller seed.
>
>Regards,
>Marcio.


Hi,
> Also, math.randomseed(0) doesn't work usefullyit seems to ignore a
seed of 0.
>
> E.g. This program:
> math.randomseed(10)
> math.randomseed(0)
> print(math.random(10),math.random(10),math.random(10))
> Just produces 4 4 3 everytime it is run...
This is because math.randomseed() uses PalmOS API SysRandom(). In this
function a zero argument means: get the next random value in the
sequence started by the previous nonzero seed, which is your example
is 10.
> What is the value of x  i.e. What is the largest number that
randomseed can manage?
The largest 32bit signed positive number, or (2^31)1.
Regards,
Marcio.

