[slang-users] Re: generating random characters

Troy Piggins troy_slang at piggo.com
Tue Feb 12 20:02:12 UTC 2008


* Michael Noble is quoted & my replies are inline below :
> > I was thinking as a workaround using the internal bash function
> > $RANDOM which generates a random number between 0 and 32767.
> 
> Will all slrn users, e.g. those on Windows, have access to bash?

No - that is one big problem with my method.

> Below is a "random" number generator I've used in several projects,
> stemming from the linear congruential method described in Knuth's
> "The Art of Computer Programming," Vol 2, Section 3.2.1.
> 
> Hope This Helps,
> Mike
> 
> ---
> 
> private variable rseed = getpid();
> private define random()
> {
>    rseed = (rseed * 0x5DEECEDL + 0xB) & ((1 shl 30) - 1);
>    (rseed shr 6) / ((1 shl 24) * 1.0);
> }

Thanks Michael.  That is a much better way than mine.  Might still prefer
John's.

-- 
Troy Piggins


More information about the slang-users-l mailing list