| 4506 | exports.chance = chance; |
| 4507 | |
| 4508 | function 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 | |
| 4530 | function chance(c) { |
| 4531 | return random() <= c; |