





 
 




 
 


On 07/17/2018 06:27 AM, Kenneth wrote:
> (BTW, I tried to find the rand() entry in the online wiki, just to see if the
> info there has changed since the latest(?) POVincluded documentation, but I
> didn't know where to look.)
most of the time i look here first:
http://wiki.povray.org/content/Reference:Keywords
Post a reply to this message


 
 




 
 


Am 17.07.2018 um 22:11 schrieb Kenneth:
> "Bald Eagle" <cre### [at] netscapenet> wrote:
>> Alain <kua### [at] videotronca> wrote:
>>
>>> All values are equally possible, including 0 and 1. The mantissa for a
>>> float is about 52 bits IIRC, so, you have a 1 in 2^52 chances of getting
>>> a 0 and the same of getting a 1. Very small but not zero chance.
>>
>> So then maybe round to the nearest Q decimal place to "compress" the range and
>> increase the likelihood of getting a 1 or a 0.
>>
>
> Compressing the range is an interesting concept, that I wasn't aware of. I'll
> give some thought to the formula presented there. But I would suspect that
> POVRay's internal rounding would be *either* 'round up' OR 'round down', but
> not both (?) In other words, a 1.0 (but never a 0.0), OR a 0.0 (but never a
> 1.0).
While that's indeed the way most floatingpoint random number generators
work  usually giving you a number ranging from 0.0 inclusive to 1.0
exclusive  POVRay's SDL random number generator is designed to be
inclusive both fenceposts.
Post a reply to this message


 
 




 
 


Jim Holsenback <ash### [at] nospamcom> wrote:
> On 07/17/2018 06:27 AM, Kenneth wrote:
> > (BTW, I tried to find the rand() entry in the online wiki, just to see if the
> > info there has changed since the latest(?) POVincluded documentation, but I
> > didn't know where to look.)
>
> most of the time i look here first:
> http://wiki.povray.org/content/Reference:Keywords
Well, that's strange (and it does indeed have info on "rand"). But I originally
looked at a different "keywords" page...
http://wiki.povray.org/content/Reference:Keywords
Clicking on "rand" there brings up no actual information, just the word itself.
:(
The wiki page that I usually look at first, as a general starting place, is...
http://wiki.povray.org/content/Documentation:Contents
... and I see now that it does indeed have the correct link to "identifiers and
keywords" but that link is located in the first paragraph of the page, which I
didn't originally notice :O I think a better place for that link would be in
the lefthand column of the page (with the other entries there), rather than in
the body of the page. And perhaps there's some confusing redundancy of 'keyword'
pages in the wiki?
Post a reply to this message


 
 




 
 


Le 180717 à 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
> 1in4billion 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 extrasafe, 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


 
 




 
 


Am 18.07.2018 um 16:38 schrieb Kenneth:
> Jim Holsenback <ash### [at] nospamcom> wrote:
>> On 07/17/2018 06:27 AM, Kenneth wrote:
>>> (BTW, I tried to find the rand() entry in the online wiki, just to see if the
>>> info there has changed since the latest(?) POVincluded documentation, but I
>>> didn't know where to look.)
>>
>> most of the time i look here first:
>> http://wiki.povray.org/content/Reference:Keywords
>
> Well, that's strange (and it does indeed have info on "rand"). But I originally
> looked at a different "keywords" page...
>
> http://wiki.povray.org/content/Reference:Keywords
I guess you mean `http://wiki.povray.org/content/Keyword`.
> Clicking on "rand" there brings up no actual information, just the word itself.
> :(
Yeah. The entire "Keyword" section of the Wiki (as opposed to the
"Reference:Keywords" page) is, to the best of my knowledge, only there
for technical reasons, related to some ageold bad decision that nobody
had the time or energy to roll back yet.
Post a reply to this message


 
 




 
 


Alain <kua### [at] videotronca> wrote:
>
> If you get scale 0, a warning is generated and the scalling will default
> to scale 1.
>
> So, no error, just a warning.
>
That's true; I probably used a poor code example to demonstrate what might occur
IF rand(...) actually hit 0.0
Post a reply to this message


 
 




 
 


"Kenneth" <kdw### [at] gmailcom> wrote:
> "Bald Eagle" <cre### [at] netscapenet> wrote:
> > Alain <kua### [at] videotronca> wrote:
> >
> > > All values are equally possible, including 0 and 1. The mantissa for a
> > > float is about 52 bits IIRC, so, you have a 1 in 2^52 chances of getting
> > > a 0 and the same of getting a 1. Very small but not zero chance.
> >
> > So then maybe round to the nearest Q decimal place to "compress" the range and
> > increase the likelihood of getting a 1 or a 0.
> >
>
> Compressing the range is an interesting concept, that I wasn't aware of. I'll
> give some thought to the formula presented there. But I would suspect that
> POVRay's internal rounding would be *either* 'round up' OR 'round down', but
> not both (?) In other words, a 1.0 (but never a 0.0), OR a 0.0 (but never a
> 1.0).
I did find the topic of rounding to be more complex than my initial naive
concept. There are different ways to do it, and it would be useful and
instructive to see examples of code that performed all the different variations.
Likewise, it would likely be useful for people writing code that requires
variations of inclusive / exclusive bounds to be able to
(0, 5) = 1, 2, 3, 4
(0, 5] = 1, 2, 3, 4, 5
[0, 5) = 0, 1, 2, 3, 4
[0, 5] = 0, 1, 2, 3, 4, 5
It would also be informative to know just what the probability of any given rand
() result is, given the starting arguments / formulation.
Post a reply to this message


 
 




 
 


Le 180718 à 20:02, Bald Eagle a écrit :
> "Kenneth" <kdw### [at] gmailcom> wrote:
>> "Bald Eagle" <cre### [at] netscapenet> wrote:
>>> Alain <kua### [at] videotronca> wrote:
>>>
>>>> All values are equally possible, including 0 and 1. The mantissa for a
>>>> float is about 52 bits IIRC, so, you have a 1 in 2^52 chances of getting
>>>> a 0 and the same of getting a 1. Very small but not zero chance.
>>>
>>> So then maybe round to the nearest Q decimal place to "compress" the range and
>>> increase the likelihood of getting a 1 or a 0.
>>>
>>
>> Compressing the range is an interesting concept, that I wasn't aware of. I'll
>> give some thought to the formula presented there. But I would suspect that
>> POVRay's internal rounding would be *either* 'round up' OR 'round down', but
>> not both (?) In other words, a 1.0 (but never a 0.0), OR a 0.0 (but never a
>> 1.0).
>
> I did find the topic of rounding to be more complex than my initial naive
> concept. There are different ways to do it, and it would be useful and
> instructive to see examples of code that performed all the different variations.
Mostly, there are 3 ways : Round down, or truncate, round to the closest
and round up.
Using int() or floor() is useful to round down.
Using ceil() is the way to round up.
Adding half of the desired interval and using int() or floor() or
subtract half the range and use int() or ceil() to round to the closest.
The advantage of floor() and ceil() is that it's easier to round to
noninteger bounds.
>
> Likewise, it would likely be useful for people writing code that requires
> variations of inclusive / exclusive bounds to be able to
>
> (0, 5) = 1, 2, 3, 4
> (0, 5] = 1, 2, 3, 4, 5
> [0, 5) = 0, 1, 2, 3, 4
> [0, 5] = 0, 1, 2, 3, 4, 5
>
>
> It would also be informative to know just what the probability of any given rand
> () result is, given the starting arguments / formulation.
>
>
Various seed() should all result in the same probabilities, but with
various sequences.
Post a reply to this message


 
 




 
 


Le 180718 à 18:55, Kenneth a écrit :
> Alain <kua### [at] videotronca> wrote:
>
>>
>> If you get scale 0, a warning is generated and the scalling will default
>> to scale 1.
>>
>> So, no error, just a warning.
>>
>
> That's true; I probably used a poor code example to demonstrate what might occur
> IF rand(...) actually hit 0.0
>
>
#declare Something = Value/rand(R);
Crash with divide by zero if rand(R) return zero.
Post a reply to this message


 
 




 
 


Am 19.07.2018 um 03:38 schrieb Alain:
>> I did find the topic of rounding to be more complex than my initial naive
>> concept. There are different ways to do it, and it would be useful and
>> instructive to see examples of code that performed all the different
>> variations.
>
> Mostly, there are 3 ways : Round down, or truncate, round to the closest
> and round up.
Actually there are a few more commonly used:
 Round towards negative infinity (round down)
 Round towards positive infinity (round up)
 Round towards zero (truncate)
 Round towards infinity of same sign
 Round to nearest ("proper" rounding)
In the latter mode, there is again a host of ways to handle values smack
in the middle between the nearest representable numbers (think 0.5):
 Round towards negative infinity (round down)
 Round towards positive infinity (round up)
 Round towards zero (truncate)
 Round towards infinity of same sign
 Round up if even, down if odd
 Round down if even, up if odd
Post a reply to this message


 
 




 

