Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: How to make weighted random numbers?
Replies: 7   Last Post: Feb 28, 2009 3:49 AM

 Messages: [ Previous | Next ]
 Mike Williams Posts: 20 Registered: 12/13/04
Re: How to make weighted random numbers?
Posted: Feb 28, 2009 1:40 AM

Wasn't it Rich Grise who wrote:

>Say, I want to fill a sphere uniformly with random dots;
>
>Either way. I don't want a uniform sphere

So you want a non-uniform sphere that's filled uniformly with dots.

The way we usually do uniform fills in POV-Ray is to calculate a random
point in the box that contains the sphere and discard those that are
outside the sphere. For efficiency, compare the square of the distance
from the centre to avoid all those square roots.

The way we usually do non-uniform spherical fills is to use some sort of
rule to generate the R parameter, then rotate the dot around the centre
by rand*360 degrees on each axis.

#declare R=seed(123);
#declare N=0;
union {
#while (N<5000)
#declare r = rand(R);
sphere {<rand(R),0,0>, 0.01
rotate <rand(R)*360,rand(R)*360,rand(R)*360>
}
#declare N=N+1;
#end
pigment {rgb <1,1,0>}
}

--
Mike Williams
Gentleman of Leisure

Date Subject Author
2/27/09 Rich Grise
2/27/09 RGVickson@shaw.ca
2/27/09 matt271829-news@yahoo.co.uk
2/27/09 swp
2/27/09 Ioannis
2/28/09 Mike Williams
2/28/09 RGVickson@shaw.ca
2/28/09 Kevin Stone