import defaultSource from "./defaultSource.js"; | |
export default (function sourceRandomGeometric(source) { | |
function randomGeometric(p) { | |
if ((p = +p) < 0 || p > 1) throw new RangeError("invalid p"); | |
if (p === 0) return () => Infinity; | |
if (p === 1) return () => 1; | |
p = Math.log1p(-p); | |
return function() { | |
return 1 + Math.floor(Math.log1p(-source()) / p); | |
}; | |
} | |
randomGeometric.source = sourceRandomGeometric; | |
return randomGeometric; | |
})(defaultSource); | |