Reference · Streams, draws and seeds
chancefunction
True with probability p, from 0 (never) to 1 (always): one draw.
Import it
import { chance } from "@johnmorrisdotca/tane";
Definition
function chance(random: Random, p: number): boolean
Parameters
| Name | Type | Description |
|---|---|---|
random | Random | A random source returning values in [0, 1). |
p | number | The probability, from 0 to 1. |
Returns
boolean
True with probability p, from 0 (never) to 1 (always): one draw.
Examples
import { chance, mulberry32 } from "@johnmorrisdotca/tane";
const random = mulberry32(42);
console.log(chance(random, 0.5));falseWhat it prints (run when this page was built)