Random.int = function(min, max) {
if (arguments.length == 0) {
min = 0;
max = Math.pow(2, 53) - 1;
}
else if (arguments.length == 1) {
max = min;
min = 0;
}
return Math.floor(Random.float(min, max));
};
Random.vec2 = function(r) {
if (typeof r == 'undefined') r = 1;
var x = 2 * Math.random() - 1;
var y = 2 * Math.random() - 1;
var rr = Math.random() * r;
var len = Math.sqrt(x*x + y*y);
return Vec2.create(rr * x / len, rr * y / len);
};
Random.vec3 = function(r) {
if (typeof r == 'undefined') r = 1;
var x = 2 * Math.random() - 1;
var y = 2 * Math.random() - 1;
var z = 2 * Math.random() - 1;
var rr = Math.random() * r;
var len = Math.sqrt(x*x + y*y + z*z);
return Vec3.create(rr * x/len, rr * y/len, rr * z/len);
};
Random.vec2InRect = function(rect) {
return Vec2.create(rect.x + Math.random() * rect.width, rect.y + Math.random() * rect.height);
};
Random.vec3InBoundingBox = function(bbox) {
var x = bbox.min.x + Math.random() * (bbox.max.x - bbox.min.x);
var y = bbox.min.y + Math.random() * (bbox.max.y - bbox.min.y);
var z = bbox.min.z + Math.random() * (bbox.max.z - bbox.min.z);
return Vec3.create(x, y, z);
};
Random.chance = function(probability) {
return Math.random() <= probability;
};
Random.element = function(list) {
return list[Math.floor(Math.random() * list.length)];
};
Random.noise2 = function(x, y) {
return simplex.noise2D(x, y);
};
Random.noise3 = function(x, y, z) {
return simplex.noise3D(x, y, z);
};
Random.noise4 = function(x, y, z, w) {
return simplex.noise4D(x, y, z, w);
};
module.exports = Random;