Skip to content

Randomness

Brandon Jordan edited this page Aug 14, 2024 · 13 revisions

Random Number

randomInt(min, max)

Random Number Generator

Spark provides an RNG class for random number generation using the same min and max.

new RNG(init, min, max);
const x = new RNG(0, 0, window.innerWidth);
x.new(); // Creates a new random value and returns it.

Random Store

A RandomStore is an extension of Store and RNG* (*just borrows the new() method).

const randomY = new RandomStore(0,0,window.innerHeight);

// Subscribe to random value.
randomY.model(() => {
    // ...
});

randomY.new(); // Subscriber gets a new random value based on min and max.
Clone this wiki locally