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

easyseed

v0.0.1

Published

A seedable random number generator.

Downloads

4

Readme

EasySeed is seedable random number generator that utilizes David Bau's seedable random number generator internally(with a few minor changes for Node.js support), and provides an easy interface for seeding and using the generator.

Note: A generator of this nature is only as random as the seed provided.

Usage

Simply require, seed, and use.

var easyseed = require('easyseed');
easyseed.seed.auto();
easyseed.float(function(n) {
    console.log(n); //0.3234234223442
});

Seeding

Before any values can be generated, the generator must be seeded. All seed types are part of the easyseed.seed namespace.

#seed.auto()

Seeds the generator with the current data/time. Useful for general purpose pseudo-random numbers.

#seed.string(str)

Seeds the generator with the specified string.

#seed.buffer(buffer)

Seeds the generator is the data within the provided buffer.

#seed.web(uri)

Makes a request for the specificed web resource and uses the response body as the seed for the generator.

#seed.file(path)

Loads a file, then uses the contents as the seed for the generator.

Getting Values

EasySeed gives you the option to get random integers or floats.

Note: Internally a queue is used to hold generation while seeding is done. This is required since some seeding options require asynchronous operations, such as making HTTP requests or reading files. This means callbacks are required for all generators.

#int([min], [mix], callback)

Generates an integer between min and max, 0 and max, or 0-1. The callback is called with the number generated.

//require and seed it...

var print = function(n) {
    console.log(n);
};

easyseed.int(print); //0 or 1
easyseed.int(10, print); //between 0 and 10
easyseed.int(50, 100, print); //between 50 and 100

#float([min], [max], callback)

Same as easyseed.int, expect a floating point number is returned. easyseed.float(callback) (no min/max) generates exactly what Math.random does.

Events

There are a couple events you can subscribe to if needed.

on('error', function(error) {})

Fires when a request of filesystem error occurs for the corresponding seed functions.

on('seeded', function(seed) {})

Fires when seeding is complete, and provides the seed string used.

Running Tests

The tests provided simply seed using all the seed functions, then generate 2000 0-1 floats (Math.random), 2000 floats between 10 and 100, and 2000 integers between 10 and 100. Node.js' Assert is used for validation. Errors are thrown if a request or filesystem error occurs.

node test.js