It appears to be evenly distributed, but I suspect the "box method" will be faster.
// random number from 0 to 1inline float random() { return (float)rand() / (RAND_MAX + 1.0f);}// generate a random point within "radius" units of the originvoid random_point(float radius, float *x, float *y, float *z) { float v1 = 2.0f * random() - 1.0f; float v2 = sqrt(1.0f - v1*v1); complex<float> v3(pow(complex<float>(v1, v2), 1.0f / 3.0f)); complex<float> v4(pow(complex<float>(v1, -v2), 1.0f / 3.0f)); complex<float> v5(-(v3 + v4 + complex<float>(0, sqrt(3.0f)) * (v3 - v4)) / 2.0f); float height = v5.real(); float flat_mag = sqrt(random()) * radius * sqrt(1 - height * height); float flat_angle = random() * 6.283185307179f; *x = cos(flat_angle) * flat_mag; *y = height * radius; *z = sin(flat_angle) * flat_mag;}