POV-Ray : Newsgroups : povray.binaries.images : Toward a less-lame rand() function. : Re: Toward a less-lame rand() function. Server Time
31 Jul 2024 18:19:12 EDT (-0400)
  Re: Toward a less-lame rand() function.  
From: Warp
Date: 15 May 2009 12:13:24
Message: <4a0d94a4$1@news.povray.org>
gregjohn wrote:
> The neatly ordered, predictable pattern of red dots in the top half of the image
> are generated with povray's rand() function.  They demonstrate what you get if
> you cause a monotonic increase in the seed value.  Once I had a project
> "ruined" by this predictable pattern because I was exploring some parameter
> space via use of the #declare RSEED=seed(frame_number).
> 
> The green dots below represent my best attempt so far to create something worthy
> of the title "random function".   It requires one first to set an "aseed" value
> between 0 and 1, but this aseed *may* increase monotonically, like #declare
> aseed=(frame_number+0.1)/(final_frame+0.1);

  The reason why you get regular patterns is because POV-Ray uses a
simple linear congruential generator as its RNG, which has this precise
flaw. LCGs are very poor-quality RNGs.

  You can try shuffling the results of the LGC around by adding
additional "garbage" to the result, but the quality of the results will
not increase. The only thing you will achieve is that in a particular
case where the original values presented regular patterns, it will stop
doing that. However, in a different case it will most probably show the
regular patterns again (because the quality of the randomness has not
increased).

  One solution would be if a new, higher-quality RNG was added to
POV-Ray internally. Perhaps it could be used with a different keyword
(such as seed2() and rand2()).


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.