slang-users mailing list

[2008 Date Index] [2008 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

[slang-users] Re: generating random characters


* John E. Davis is quoted & my replies are inline below :
> Michael Noble <mnoble@xxxxxxxxxxxxx> wrote:
> > private variable rseed = getpid();
> > private define random()
> >{
> >    rseed = (rseed * 0x5DEECEDL + 0xB) & ((1 shl 30) - 1);
> >    (rseed shr 6) / ((1 shl 24) * 1.0);
> >}
> 
> Another one that is ok for the purposes Troy has in mind is:
> 
>   private variable Random;
>   define srandom (r)
>   {
>      Random = r;
>   }
>   srandom (_time() * getpid());
> 
>   define random ()
>   {
>      Random = (Random*69069U + 1013904243U)&0xFFFFFFFFU;
>      return Random;
>   }
>   define urandom ()
>   {
>      return random()/4294967296.0;
>   }

Excellent - that'll do nicely.  Thankyou.

> Here, urandom() returns a random number between 0 and 1, whereas
> random returns a random unsigned integer between 0 and 0xFFFFFFFF.
> 
> FWIW, the next slang release (2.1.4) will include a random number
> module.  The module will feature a generator that according to the
> "dieharder" battery of tests has slightly better statistical
> properties than the Mersenne Twister and is about as fast.   This
> module is not yet in the svn repository but will appear on the next
> update.

Interesting - thanks for that.

-- 
Troy Piggins



[2008 date index] [2008 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]