npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

squirrel-noise-5

v1.5.0

Published

Noise based RNG tool

Downloads

21

Readme

Squirrel Noise 5

squirrel-noise-5 is a utility to generate deterministic random numbers.

This an adaptation of Squirrel Eiserloh's: Squirrel's Raw Noise utilities (version 5)

Squirrel Eiserloh's original GDC talk on YouTube: Noise-Based RNG

Newer version since the GDC talk, Squirrel Noise 5 (with improved statistical quality with some help from mathematician Peter Schmidt-Nielsen): Squirrel Noise 5

Description

This allows generation of seeded sequential random values, seeded tables of random values (1D, 2D, 3D, 4D). All of these are order independant and allow for random access.

Changes I made compared to the C++ version:

The first change I made was inside the SquirrelNoise5 function. I used 64 bit integer space during addition and multiplication steps, and then immediately converted back to an unsigned 32 bit integer. This achieved bit perfect results when compared against the original C++ code output.

The second change is for the functions that return a decimal between x and y, the C++ floats only return 6-9 digits after the decimal. This javascript version returns quite a few more decimal places. Rather than try to round it to make it exactly the same, I left it as is as I couldn't think of a scenario where more precision would hurt.

Installation

npm i squirrel-noise-5

Usage

Static example

import SquirrelRNG from 'squirrel-noise-5';

const index = 0;
const seed = 123456;
const randomIntValue = SquirrelRNG.Get1dNoiseUint(index, seed);
const randomFloatValue = SquirrelRNG.Get1dNoiseZeroToOne(index, seed);

Instance example

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);

Static 2D example

import SquirrelRNG from 'squirrel-noise-5';

const playerSeed = 123456;
const playerCoordinates = { x: 300, y: 72 };
const randomIntValue = SquirrelRNG.Get2dNoiseUint(
  playerCoordinates.x,
  playerCoordinates.y,
  playerSeed
);

Instance random access example

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);

How to run the unit tests

npm install -D vitest
npm run test

Authors and acknowledgment

I want to thank the original author Squirrel Eiserloh for making this available to the public.

License

CC BY-SA 4.0