/**
 * Unit sphere sampling
 * @see based on python code suggested here: https://stackoverflow.com/questions/5408276/sampling-uniformly-distributed-random-points-inside-a-spherical-volume
 * @param {function} random
 * @param {number[]|Float32Array} result
 * @param {number} result_offset
 */
export function randomPointOnSphere(random, result, result_offset) {
    const phi = Math.PI * 2 * random();

    const cosTheta = random() * 2 - 1;

    const theta = Math.acos(cosTheta);

    const sinTheta = Math.sin(theta);

    //compute coordinates
    const x = sinTheta * Math.cos(phi);
    const y = sinTheta * Math.sin(phi);
    const z = cosTheta;

    //write the result
    result[result_offset] = x;
    result[result_offset + 1] = y;
    result[result_offset + 2] = z;
}
