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


* 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



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