POV-Ray : Newsgroups : povray.binaries.images : Toward a less-lame rand() function. : Re: Toward a less-lame rand() function. Server Time
1 Aug 2024 00:18:15 EDT (-0400)
  Re: Toward a less-lame rand() function.  
From: clipka
Date: 19 May 2009 16:30:00
Message: <web.4a1314f42a89ae6d14a420210@news.povray.org>
"Kenneth" <kdw### [at] earthlinknet> wrote:
> IIRC, you mentioned something several ago (to me) that seed() chooses it
> 'starting point' in the stream in a very complex fashion...not just 'linearly'
> in the stream.  IOW, the difference between seed(23) and seed(24) isn't just
> jumping one value ahead in the 2^32 stream. Is my thinking correct?

Yes. In a first approach, think of seeding the RNG as fast-forwarding to the
position in the 2^32 stream at which that very number appears, so it would not
make a difference (except for speed) whether you would call seed(23), or
instead pull and discard numbers from the stream until the value you pull is 23
(which you discard as well).

Admittedly, this is a bit oversimplified: In real-life RNGs, that 23 is almost
always hidden from your view, and what you get when pulling from the stream is
actually some hash of it (in some primitive RNGs just to make it fit the
desired output range, while in high-quality RNGs it also serves to "distill"
all the "randomness" from a huge but relatively low-random "raw" value into a
small but relatively high-random number).

So to do the stunt of replacing seed() with a lot of dummy calls to rand() you'd
have to know what that 23 is hashed into. And with higher-quality RNGs various
"raw" values will result in identical output numbers, so from pulling a number
from the stream you still cannot tell where in the stream you currently are,
making that stunt impossible.


Post a reply to this message

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