Bug in RealRandom.Spin
Heater.
Posts: 21,230
I just downloaded RealRandom.spin from the OBEX (Version 1.1) and noticed an error in the start method:
Basically it has a line of code after "return" that is never executed. This could result in some applications not getting random numbers for a while immediately after starting RealRandom.
I guess for most it would not notice or matter but I wanted to start RealRandom for a very short time, get some values for an initial seed of a PRNG with a very long period and then shut down RealRandom. Rather than dedicating a COG to random numbers.
Basically it has a line of code after "return" that is never executed. This could result in some applications not getting random numbers for a while immediately after starting RealRandom.
I guess for most it would not notice or matter but I wanted to start RealRandom for a very short time, get some values for an initial seed of a PRNG with a very long period and then shut down RealRandom. Rather than dedicating a COG to random numbers.
PUB start : okay '' Start real random driver - starts a cog '' returns false if no cog available 'Reset driver stop 'Launch real random cog return cog := cognew(@entry, @random_value) + 1 'allow 5ms to launch and randomize waitcnt(clkfreq / 200 + cnt)
Comments
-Phil
The first random number returned is always zero.
So if I use it as a seed for my long period PRNG it is not so good! So the delay to let things start up has to be placed some where.
Further experiment shows that this:
Gets "random rumbers" of zero all the way up to l.