|
![](/i/fill.gif) |
In article <3e4a9fe0@news.povray.org>, Warp <war### [at] tag povray org>
wrote:
> In the man page of rand() in some Unix variant (don't remember which)
> there was a note that the lowest bit of the number returned by rand() should
> not be used because it alternates between 0 and 1 in successive calls.
>
> Makes one wonder if it wouldn't be better to fix the problem instead
> of documenting it... :)
Maybe there was some other constraint that kept them from doing
so...performance, etc. Or maybe they just didn't know anything about
PRNG's.
In any case, I never use rand(). I occasionally use random(). From the
manpage:
The random() function uses a non-linear additive feedback random
number generator employing a default table of size 31 long
integers to return successive pseudo-random numbers in the range
from 0 to (2**31)-1. The period of this random number generator
is very large, approximately 16*((2**31)-1).
The random() and srandom() functions have (almost) the same
calling sequence and initialization properties as the rand(3) and
srand(3) functions. The difference is that rand(3) produces a
much less random sequence -- in fact, the low dozen bits generated
by rand go through a cyclic pattern. All the bits generated by
random() are usable. For example, `random()&01' will produce a
random binary value.
It is pretty simple to create a wrapper class for it. Usually I use a
Mersenne Twister class I wrote. (Meaning of course that I wrote the
class, much of the code is very close to the original implementation by
Makoto Matsumoto and Takuji Nishimura.)
This is the random number generator I used in Sapphire.
--
Christopher James Huff <cja### [at] earthlink net>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: chr### [at] tag povray org
http://tag.povray.org/
Post a reply to this message
|
![](/i/fill.gif) |