POV-Ray : Newsgroups : povray.documentation.inbuilt : revisiting rand(...) : Re: revisiting rand(...) Server Time
25 Oct 2021 03:30:51 EDT (-0400)
  Re: revisiting rand(...)  
From: Alain
Date: 18 Jul 2018 12:23:45
Message: <5b4f6991$1@news.povray.org>
Le 18-07-17 à 17:25, Kenneth a écrit :
> clipka <ano### [at] anonymousorg> wrote:
> 
>>
>> Theoretically and without too detailed analysis(*), the random number
>> generator should be able to generate 2^32 (approx. 4 [short] billion)
>> different results, including both 0.0 and 1.0. So unless you did your
>> experiment with 200 different seeds, you're still far from the threshold
>> where you could expect /any/ particular result value crop up for sure.
>>
> 
> I do see your point (and Alain's): Let's say I write some code where I naively
> *expect* a rand() value of 0.0 or 1.0 to pop up every now and then (well, with a
> 1-in-4-billion chance, assuming *equal* probability.) But those are distinct,
> specific values-- it would be like expecting the exact value of .4729418830...
> to pop up now and again. Which is highly unlikely (but still possible.)
> 
> But there's a practical aspect to consider, when writing a typical scene using
> rand()-- if my own experience is any indication:
> 
> Let's say I want to make 10,000,000 stars in the sky. My own current way of
> doing this (simplified) would be...
> 
> union{
> #for(i,1,10000000)
> sphere{0,1 scale 100*rand(R)
> translate ...
> }
> #end
>    texture{...}
> }
> 
> .... and I would ignore the *remote* possibility of rand() being 0.0, and thus
> scale being <0.0,0.0,0.0>, which would trigger an error. Yet this *seems* to be
> the behavior of rand(), in a practical sense, so I always feel safe in ignoring
> that possibility.
> 
> But to be extra-safe, the code *should* be something like this...
> ....
> sphere{0,1 scale 100*(rand(R) + "some tiny positive value")
> ....
> 
> .... even though rand() 'never' hits exactly 0.0, in my experience.
> 
> 
> 
> 
> 

If you get scale 0, a warning is generated and the scalling will default 
to scale 1.

So, no error, just a warning.


Alain


Post a reply to this message

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