MCPcopy Create free account
hub / github.com/codrops/RainEffect / random

Function random

demo/js/main.js:4508–4528  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4506exports.chance = chance;
4507
4508function random() {
4509 var from = arguments.length <= 0 || arguments[0] === undefined ? null : arguments[0];
4510 var to = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];
4511 var interpolation = arguments.length <= 2 || arguments[2] === undefined ? null : arguments[2];
4512
4513 if (from == null) {
4514 from = 0;
4515 to = 1;
4516 } else if (from != null && to == null) {
4517 to = from;
4518 from = 0;
4519 }
4520 var delta = to - from;
4521
4522 if (interpolation == null) {
4523 interpolation = function (n) {
4524 return n;
4525 };
4526 }
4527 return from + interpolation(Math.random()) * delta;
4528}
4529
4530function chance(c) {
4531 return random() <= c;

Callers 1

chanceFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected