infinite-sequencer
v1.0.0
Published
Generate pseudo-random sequences of infinite lenght
Downloads
1
Readme
Sequencer
Create infinite-length sequences from your iterables
const {
XorShift,
AbstractSequencer,
NaiveSequencer,
DeduplicationSequencer
} = require('infinite-sequencer');
const arr = [1,2,3,4,5,6];
const seq = new NaiveSequencer(arr);
while(true) {
seq.next(); // {value: number, done: false}
}
AbstractSequencer(sequence, prng)
Abstract class, provides methods next
and getter size
. Subclasses must implement method getNextValue
, returning value.
sequence
must be an finite iterableprng
must be either object with methodrandom
, returning number from 0 to 1. Default toMath
builtin object.
NaiveSequencer(sequence, prng)
Generates stream of random values from sequence.
DeduplicationSequencer(sequence, prng, {rate, lastEntriesCount, flip})
Generates stream of random values. Drawing a value lowers chance of getting the same value in lastEntriesCount
next items.
Optimized for human skewed sense of "randomness".
rate=0.5
- chance to redraw, compared to result offlip
flip(randomValue: Number, i: Int32, lastItemsPositions: Int32[])
- function to determine chances. Defaults to identity -randomValue=>randomValue
.lastEntriesCount=5
- determines number last elements to check.