↩ī¸Ž

sample-size

🎲 pass/fail by sample size

Accepts one decimal fraction

const sample = require('sample-size');

filter(0) // always false

filter(1) // always true

filter(.2) // about 20% true

Usage examples

Report only about 5% of events

sample(.05) && reportEvent();

Sample about half of a list

array.filter(() => sample(.5));

Transpiled version

Environments which exclude node_modules from the transpiling pipeline should include the "browser" entry instead of "main". This exposes an ES5 commonjs module.

Also available for explicit import:

const sample = require('sample-size/dist');