UNPKG

toosoon-prng-controllers

Version:

This project provides PRNG functions with a set of controllers for generating pseudo-random values using a seed-based approach

42 lines (41 loc) 1.03 kB
import { PRNG as BasePRNG } from 'toosoon-prng'; /** * Utility class for generating pseudo-random values and managing controllers * * @class PRNG * @extends BasePRNG */ class PRNG extends BasePRNG { controllers = []; /** * Set this PRNG seed * * @param {Seed} seed */ setSeed(seed) { if (this.seed === `${seed}`) return; super.setSeed(seed); this.controllers.forEach((controller) => controller.getValue()); } /** * Add a controller to this PRNG * * @param {PRNGController} controller Controller to add */ addController(controller) { this.controllers.push(controller); } /** * Remove a controller from this PRNG * * @param {PRNGController} controller Controller to remove */ removeController(controller) { const index = this.controllers.indexOf(controller); if (index >= 0) this.controllers.splice(index, 1); } } const prng = new PRNG(); export default prng;