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

random-seed

v0.3.0

Published

GRC's UHE PRNG in node (Ultra-High Entropy Pseudo-Random Number Generator by Gibson Research Corporation)

Downloads

668,327

Readme

random-seed

NPM version Build Status Code Climate Coverage Status Dependency Status devDependency Status

NPM

Description

Gibson Research Corporation's Ultra-High Entropy Pseudo-Random Number Generator ported to node.

The original library / project page is located here: https://www.grc.com/otg/uheprng.htm

The node project page is here: https://github.com/skratchdot/random-seed

There were a few modifications made to the original library to allow seeding, and to pass jshint.

I've also added the following helper methods:

  • random()
  • range(range)
  • floatBetween(min, max)
  • intBetween(min, max)

Getting Started

Install the module with: npm install random-seed

var rand = require('random-seed').create();
var n = rand(100); // generate a random number between 0 - 99

Documentation

Create a random number generator

var gen = require('random-seed'); // create a generator

// these generators produce different numbers
var rand1 = gen.create(); // method 1
var rand2 = new gen();    // method 2
var rand3 = gen();        // method 3

// these generators will produce
// the same sequence of numbers
var seed = 'My Secret String Value';
var rand4 = gen.create(seed);
var rand5 = new gen(seed);
var rand6 = gen(seed);

Random Generator Methods

Once a random generator is created, you have the following methods available.

I typically create a random generator like this:

var rand = require('random-seed').create();

rand(range)

Returns a random integer between 0 (inclusive) and range (exclusive)

rand.range(range)

Returns a random integer between 0 (inclusive) and range (exclusive)

rand.random()

Returns a random float between 0 (inclusive) and 1 (exclusive)

Works the same as Math.random()

rand.floatBetween(min, max)

Returns a random float between min (inclusive) and max (exclusive)

rand.intBetween(min, max)

Returns a random integer between min (inclusive) and max (inclusive)

rand.seed(seed)

Same as calling rand.initState() followed by rand.hashString(seed). If seed is not a string, then the seed value will be converted to a string. If you don't pass a seed argument, then the generator uses Math.random() as the seed.

rand.string(count)

Returns a pseudo-random string of 'count' printable characters ranging from chr(33) to chr(126) inclusive.

rand.cleanString(inStr)

Removes leading and trailing spaces and non-printing control characters, including any embedded carriage-return (CR) and line-feed (LF) characters, from any string it is handed. This is also used by the 'hashstring' function (below) to help users always obtain the same EFFECTIVE uheprng seeding key.

rand.hashString(inStr)

Hashes the provided character string after first removing any leading or trailing spaces and ignoring any embedded carriage returns (CR) or Line Feeds (LF).

rand.addEntropy(/* accept zero or more arguments */)

This handy exported function is used to add entropy to our uheprng at any time.

rand.initState()

If we want to provide a deterministic startup context for our PRNG, but without directly setting the internal state variables, this allows us to initialize the mash hash and PRNG's internal state before providing some hashing input.

rand.done()

We use this (optional) exported function to signal the JavaScript interpreter that we're finished using the internal "Mash" hash function so that it can free up the local "instance variables" it will have been maintaining. It's not strictly necessary, of course, but it's good JavaScript citizenship.

Examples

Default Usage: create 1 random number between 0 - 99

var rand = require('random-seed').create();
var n = rand(100); // generate a random number between 0 - 99

Always create same sequence of random numbers

var rand = require('random-seed').create();
rand.initState();
var n1 = rand(100); // n1 === 58
var n2 = rand(100); // n2 === 26
rand.initState();   // re-init
var n3 = rand(100); // n3 === 58 && n3 === n1

Create 2 random number generators

var rand1 = require('random-seed').create(),
	rand2 = require('random-seed').create();
console.log(rand1(100), rand2(100));

Create 2 random number generators with the same seed

var seed = 'Hello World',
	rand1 = require('random-seed').create(seed),
	rand2 = require('random-seed').create(seed);
console.log(rand1(100), rand2(100));

Replace Math.random()

var math = require('random-seed').create();
console.log(math.random());

Release History

v0.2.0 (Released June 1, 2014)

  • Adding the following helper methods:
    • rand.random(min, max)
    • rand.floatBetween(min, max)
    • rand.intBetween(min, max)

v0.1.0 (Released October 26, 2013)

  • Initial Release

License

Copyright (c) 2013 skratchdot

Dual Licensed under the MIT license and the original Public Domain License by GRC.