POV-Ray : Newsgroups : povray.documentation.inbuilt : revisiting rand(...) : Re: revisiting rand(...) Server Time
17 Sep 2021 22:40:42 EDT (-0400)
  Re: revisiting rand(...)  
From: Kenneth
Date: 17 Jul 2018 17:30:00
Message: <web.5b4e5ed114e7ffaca47873e10@news.povray.org>
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...

sphere{0,1 scale 100*rand(R)
translate ...

.... 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.

Post a reply to this message

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