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

pringle

v1.1.1

Published

Fast pseudorandom number generator

Downloads

29

Readme

pringle

Fast pseudorandom number generator

JavaScript adaptation of the pseudorandom number generator from the 2008 research paper Evolving Sub-Grid Turbulence for Smoke Animation [PDF] by H. Schechter and R. Bridson of the The University of British Columbia, Canada. which in turn uses the research paper Wavelet Noise [PDF] by Robert L. Cook Tony DeRose of Pixar Animation Studios for the PRNG.

This algorithm is small, fast and in most cases random enough.

PRNG

A PRNG (pseudorandom number generator) always generates the same sequence of random numbers. You can change the sequence by supplying a different seed. This is very useful if you always want the same sequence of random numbers.

Install

To install, type in the console:

npm install pringle

Import

Preferred: load pringle as a JavaScript module using a bundler like webpack or Rollup:

import { Prng } from "pringle";

Load pringle dynamically as a JavaScript module (no bundler needed, like in demo.js):

const {Prng} = await import( "./pringle.js" );

API

prng = new Prng(seed);

Initialise Prng with a seed (any number).

const r = prng.rand();

Returns a floating point number 0 and 1.

This is including 0, excluding 1, so prng.rand() can return 0, but will never return 1.

const r = prng.rand(max);

Returns a floating point number between 0 and max.

const r = prng.rand(min, max);

Returns a floating point number between min and max.

const i = prng;

prng can be used as an endless iterator of random numbers.

let count = 5;
for (const r of prng) {
    doSomething(r);
    if (count-- == 0) {
        break;
    }
}

const i = prng.iter(count);

Returns an iterable returning count random numbers between 0 and 1.

You can use the iterable in a for loop like this:

for (const r of prng.iter(5)) {
    doSomething(r);
}

Another example of using the iterator is generating an array of 5 random integers between 0 and 10:

const arr = Array.from(prng.iter(5), (r) => Math.floor(r * 10));

const r = prng.prng();

Returns the raw value of the generator, a 32 bit signed integer (between -2,147,483,648 and 2,147,483,647, inclusive).

Normally, you use prng.rand() instead of this function.

Demo

In the file demo.js, you can see examples of using the API.

You can run it in the console by typing:

npm run demo

Naming

Pringle is named after the American actress Aileen Pringle (1895-1989). It's unrelated to some brand of potato-based crisps.

License

Copyright 2022 Edwin Martin and released under the MIT license.