POV-Ray : Newsgroups : povray.documentation.inbuilt : revisiting rand(...) : Re: revisiting rand(...) Server Time
7 Oct 2024 07:18:59 EDT (-0400)
  Re: revisiting rand(...)  
From: Alain
Date: 17 Jul 2018 11:11:24
Message: <5b4e071c$1@news.povray.org>
Le 18-07-17 à 06:27, Kenneth a écrit :
> I'm wondering about the documentation for rand(...).
> 
> It has stated for a long time that the values that rand produces are "between
> 0.0 and 1.0, inclusive." But in all my uses of it in scenes, the value never
> actually hits those exact values. (Some of my code would actually have a problem
> if that happened; but I've never encountered such a problem... which is why I
> now ignore the 'inclusivity.')
> 
> On a whim, I ran some tests (with different seed(...) values)-- 10,000,000 tries
> each time. But I haven't yet seen a 1.0 or a 0.0 occur.
> 
> #declare S = seed(17);
> #for(i,1,10000000)
> #declare R = rand(S);
> #if(R = 0.0 | R = 1.0)
> #debug concat("\n","rand = ",str(R,1,6),"\n")
> #else
> #end
> #end
> 
> Unless there *is* a one-in-a-gazillion chance of it happening (uh, like the
> decay of a proton, for example), I think the docs should say, "between 0.0 and
> 1.0, exclusive."
> 
> (BTW, I tried to find the rand() entry in the online wiki, just to see if the
> info there has changed since the latest(?) POV-included documentation, but I
> didn't know where to look.)
> 
> 

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.


Post a reply to this message

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