Skip to content
Matt Bierner edited this page Nov 8, 2015 · 1 revision

Apep by default uses Math.random for selecting elements in a choice. For testing though, you may need to know exactly what values will be produced.

Every execution function takes an optional random number generator function as its last argument:

const p = pep.choice('a', 'b', 'c');

const notSoRandom = () => 0.5;

pep.run(p, null /*ud*/, notSoRandom) === 'b'
p.run(null /*ud*/, notSoRandom) === 'b'

The random number generator is a function that takes zero arguments and produces a value between zero and one. Choice uses walker-sample with the Walker Alias method for random selection in O(1) time. Each choice makes two calls to the random number generator.

Clone this wiki locally