rhb-server/mes-ui/rhb-app/node_modules/gl-vec2/random.js
2025-10-20 11:14:41 +08:00

16 lines
433 B
JavaScript

module.exports = random
/**
* Generates a random vector with the given scale
*
* @param {vec2} out the receiving vector
* @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned
* @returns {vec2} out
*/
function random(out, scale) {
scale = scale || 1.0
var r = Math.random() * 2.0 * Math.PI
out[0] = Math.cos(r) * scale
out[1] = Math.sin(r) * scale
return out
}