|
|
Ron Parker <ron### [at] povrayorg> wrote:
: next_rand[stream] = next_rand[stream] * 1812433253L + 12345L;
: which doesn't look particularly well-chosen to me.
It depends on what you want to do, but basically you are right, it's not
excellent.
There are better methods which give more randomness and much large periods.
For example the C library function (not standard but found in most unix
compilers and perhaps others as well) for random() is described in the
following way:
The random() function uses a nonlinear additive feedback
random-number generator employing a default state array size
of 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 approximately 16 x (2**31-1). The
size of the state array determines the period of the
random-number generator. Increasing the state array size
increases the period.
If I understand this correctly, it uses a whole array as seed value instead
of one integer. I suppose that this way more randomness is achieved and
a much larger period (16*(2^31-1) is pretty large).
--
char*i="b[7FK@`3NB6>B:b3O6>:B:b3O6><`3:;8:6f733:>::b?7B>:>^B>C73;S1";
main(_,c,m){for(m=32;c=*i++-49;c&m?puts(""):m)for(_=(
c/4)&7;putchar(m),_--?m:(_=(1<<(c&3))-1,(m^=3)&3););} /*- Warp -*/
Post a reply to this message
|
|