```Date: Feb 27, 2009 10:09 PM
Author: RGVickson@shaw.ca
Subject: Re: How to make weighted random numbers?

On Feb 27, 6:36 pm, Rich Grise <r...@example.net> wrote:> Say, I want to fill a sphere uniformly with random dots; the logical way> to do that in r,theta format;No. That would not fill the sphere uniformly (unless you had a non-uniform distribution with respect to the radius). Probably the easiestway, for a sphere of radius r, is to do it for a sphere of radius 1and then scale up (or down) all dimensions by the factor r. So, for asphere of radius 1, choose three coordinates (X,Y,Z) independently andat random between -1 and +1; accept the point (X,Y,Z) if X^2 + Y^2 +Z^2 <= 1; otherwise, reject the point and generate another point(X,Y,Z), etc. It is easy to show that the accepted points areuniformly distributed throughout the sphere. Of course, some generatedpoints are wasted, but the ratio of accepted points to total pointsgenerated = Volume(sphere)/Volume(cube of side 2) = 0.5236, so about52% of the generated points get accepted. If generating random numbersis cheap compared to other computations, then wasting 48% of thegenerated points may still be cheaper and more efficient than someother methods.R.G. Vickson> otherwise to make a sphere, you'd have to> do  some heroic math on the three dimension (or is there some> quick-n-dirty formula that can do it in one flop, that they don't tell> us high school (and Tech School, don't forget!) ?>> Either way. I don't want a uniform sphere - more like density through the> center looks like a bell-shaped curve, i.e., denser in the middle?>> It's got to be computable, maybe with iterations, but that's what I> do best! I just have no idea what the algorithm would be.>> What I'm up to is I have a 3-d drafting program and I want to approximate> a translucent ball effect. I can enter coordinates by copying the output> and paste it into the command line to automatically place n dots. ;-)>> Thanks!> Rich
```