UNPKG

@thi.ng/random

Version:

Pseudo-random number generators w/ unified API, distributions, weighted choices, ID generation

6 lines (5 loc) 230 B
import { SYSTEM } from "../system.js"; const geometric = (rnd = SYSTEM, p = 0.5) => p <= 0 ? () => Infinity : p >= 1 ? () => 1 : (p = Math.log(1 - p), () => Math.floor(Math.log(1 - rnd.float(1)) / p) + 1); export { geometric };