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

@szydlovski/alea

v0.1.1

Published

seedable random, an implementation of Johannes Baagøe's Alea

Downloads

30

Readme

alea

Seedable random, an implementation of Johannes Baagøe's Alea algorithm. Mostly a refactored copy paste with the addition of some convenience methods.

Usage

npm install @szydlovski/alea
const Alea = require('@szydlovski/alea');

// will always produce the same numbers for the same seed
new Alea('seed1').next() // 0.061422935919836164
new Alea('seed1').next() // 0.061422935919836164
new Alea('seed2').next() // 0.37036016467027366

const generator = new Alea('seed');
for (let i = 0; i++ < 100;) {
  generator.next();
}
// two ways to clone an existing generator
const clone1 = new Alea().importState(generator.exportState());
const clone2 = generator.clone();

generator.next(); // 0.6304205257911235
clone1.next(); // 0.6304205257911235
clone2.next(); // 0.6304205257911235

API

new Alea([, seed])

Creates a new instance, optionally using a seed, otherwise the current date is used. The seed will be stringified using toString.

Alea.next()

Generates and returns the next random number between 0 and 1.

Alea.random()

Alias of Alea.next.

Alea.exportState()

Returns a copy of the instance's internal state, in the form of an array containing four numbers.

Alea.importState(state)

Imports a given state into the instance. The state should be an array containing four numbers, like the array returned by Alea.exportState. Returns the instance, allowing for chained calls like:

const generator = new Alea().importState(state);

Alea.clone()

Clones the instance. This is the equivalent of:

const clone = new Alea().importState(instance.exportState());

License

Copyright (C) 2010 by Johannes Baagøe [email protected]

Copyright (C) 2020 by Kamil Szydlowski [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.