The Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » sci.math.* » sci.math

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   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
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2017. All Rights Reserved.