4 ms·
The method I immediately think of is just based on the relation. Sqrt(x^2 + y^2 +z^2) <= 1 reduces to x^2 + y^2 +z^2 <= 1 Generate the random value for x^2, a
by goldenkey 8y ago
The method I immediately think of is just based on the relation.
Sqrt(x^2 + y^2 +z^2) <= 1
reduces to
x^2 + y^2 +z^2 <= 1
Generate the random value for x^2, any random value <= 1
Now we have y^2 +z^2 <= 1-x^2
Generate a random value for y^2, any random value <= 1-x^2
Finally generate a random value for z^2, any random value <= 1-x^2-y^2
Take the square roots of each number we generated to get the final coordinates.
But wait! Theres another step..the most important one! There are 6 orderings of (x,y,z) We must choose a random one because otherwise x will be biased towards higher values compared to y and z.
So I kind of lied. All we needed was 3 random values via the subtraction methods above. Then we need to randomly choose their ordering as (#,#,#)
This seems like the easiest most trivial solution that would be uniformly distributed.
Let me know if I am wrong.
- kgwgk 8y agoYou are wrong.
- machiavelli1024 8y ago>Let me know if I am wrong. You're wrong on multiple levels. 1. Generating random values for x^2, y^2, z^2 and taking their square root will only give you values in the x,y,z > 0 octant. (But let's say you "fix" this by randomly multiplying them with -1.) 2. Taking the square root of a uniformly distributed random variable is no longer uniformly distributed. 3. Randomly reordering the coordinates won't fix your bias. Here's a demonstration in 2D: https://jsfiddle.net/tz85wnxy/59/ https://jsfiddle.net/tz85wnxy/59/ Uncomment line 17, 18, 20 to see how it's still not uniform even if you randomly multiply the coordinates by -1 and reorder them.
- goldenkey 8y agoWorks fine as long as you generate x,y,z randomly and not their squares. Same process but minor tweak. https://jsfiddle.net/w8zLvsy2/ https://jsfiddle.net/w8zLvsy2/
- machiavelli1024 8y agoNope. You still have clustering on the sides. A proper uniform distribution would produce the same grey shade all over the circle, like this: https://jsfiddle.net/tz85wnxy/86/ https://jsfiddle.net/tz85wnxy/86/ Yours have darker areas on the sides.
- cvoss 8y agoThis approach is still incorrect, and the bias toward the set of 4 points S = {(1,0),(-1,0),(0,1),(0,-1)} can be seen in the diagram. There is no way to break out of this bias by flipping or reordering coordinates because those two operations preserve the symmetries of S: - if you flip the x-coord of a point near S, e.g. (-.9,0), you still get a point near S, e.g. (.9,0) - if you swap the x-coord and y-coord of a point near S you still get a point near S. - etc.