# random-seed

0.3.0 • Public • Published

# random-seed

## 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`

## Documentation

### Random Generator Methods

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

I typically create a random generator like this:

#### 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.

## 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

## Package Sidebar

### Install

`npm i random-seed`

### Repository

github.com/skratchdot/random-seed

### Homepage

github.com/skratchdot/random-seed

152,092

0.3.0