Noise based RNG tool
squirrel-noise-5 is a utility to generate deterministic random numbers.
npm i squirrel-noise-5
`
Usage
$3
`javascript
import SquirrelRNG from 'squirrel-noise-5';
const index = 0;
const seed = 123456;
const randomIntValue = SquirrelRNG.Get1dNoiseUint(index, seed);
const randomFloatValue = SquirrelRNG.Get1dNoiseZeroToOne(index, seed);
`
$3
`javascript
import SquirrelRNG from 'squirrel-noise-5';
const position = 0;
const seed = 123456;
const rng = new SquirrelRNG(seed, position);
// Roll a D20
const randomIntValue = rng.rollRandomIntInRange(1, 21);
// Roll a D20 again
const randomIntValue2 = rng.rollRandomIntInRange(1, 21);
`
$3
`javascript
import SquirrelRNG from 'squirrel-noise-5';
const playerSeed = 123456;
const playerCoordinates = { x: 300, y: 72 };
const randomIntValue = SquirrelRNG.Get2dNoiseUint(
playerCoordinates.x,
playerCoordinates.y,
playerSeed
);
`
$3
`javascript
import SquirrelRNG from 'squirrel-noise-5';
const seed = 123456;
const gameRound = 12;
const rng = new SquirrelRNG(seed, gameRound);
// Roll a D20
const randomIntValue = rng.rollRandomIntInRange(1, 21);
// Position incremented to 13 internally, set it back to 12.
rng.setPosition(gameRound);
// Roll a D20, result will be the same as the first roll.
const randomIntValue2 = rng.rollRandomIntInRange(1, 21);
`
$3
`
npm install -D vitest
npm run test
``