UNPKG

@fimbul-works/vec

Version:

A comprehensive TypeScript vector math library providing 2D, 3D, and 4D vector operations with a focus on performance and type safety.

8 lines (7 loc) 406 B
import { fromSphericalCoords3D } from "./from-spherical-coords-3d.js"; /** * Creates a random unit 3D vector. * @param {() => number} random - A function that returns a random number between 0 and 1 (default: `Math.random`) * @returns {ArrayVector3D} Random unit vector */ export const random3D = (random = Math.random) => fromSphericalCoords3D(Math.acos(2 * random() - 1), random() * Math.PI * 2, 1);