POV-Ray : Newsgroups : povray.newusers : Using rand(); clear howto! : Re: Using rand(); clear howto! Server Time
5 Sep 2024 08:19:17 EDT (-0400)
  Re: Using rand(); clear howto!  
From: Chris Huff
Date: 10 May 2001 22:49:21
Message: <3afb5330@news.povray.org>
Simon Lemieux <lem### [at] yahoocom> wrote: 

> I'm currently trying to use rand to determine random location of
> objects in my scene.  I would like rand to give the exact same
> result every time it runs.

It will do this on its own, you have to go through special effort to
get it to work differently.


> Here is an example of code that should normally give a cloud of
> dots, brighter if there is more objects with antialiasing:

> #declare n = 100 *2;
> #declare i = 0;
> #declare b = 3;
> #while (i<n)

> sphere { <rand(seed(i)), rand(seed(i+1)), 0>, 0.01 pigment { color rgb 1 }
> finish { ambient 1 } translate <-0.5, -0.5, 0> scale 2}

> #declare i = i+2;
> #end

> But this code give two Very well aligned lines (made of dots...),
> what is the problem?

You are not only seeding the random number generator within the loop,
you are seeding it *for every call*. You need to create one stream and
use it.
(And some general advice, always use at least one capital letter in
variable names, to avoid possible conflict with future features...and
indent!)

#declare N = 100*2;
#declare I = 0;
#declare S = seed(54321);
#while (I<N)
    sphere { <rand(S), rand(S), 0>, 0.01
        pigment { color rgb 1 }
        finish { ambient 1 }
        translate <-0.5, -0.5, 0>
        scale 2
    }
    #declare I = I+2;
#end

And of course, this will only make random spheres in a plane, for a 3D
cloud you need to add a third rand(S) to the sphere location vector.

-- 
Christopher James Huff - chr### [at] maccom
Home Page: http://homepage.mac.com/chrishuff/
POV-Ray TAG e-mail: chr### [at] povrayorg
POV-Ray TAG web site: http://tag.povray.org/


Post a reply to this message

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