New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gnrng

A minimal seeded random number generator.

1.0.2
latest
Version published
Weekly downloads
3
-50%
Maintainers
1
Weekly downloads
 
Created

gnrng

A minimal seeded random number generator that generates numbers between -1 and 1. Adapted from the more full-featured seedrandom (and using xorshift), though chances are this is all you need.

Pronounced "grrrngg".

Installation

npm i gnrgn

or

yarn add gnrng

Usage

Call rng with a string as the generator's seed and receive a new function in return. Call this function to produce a random number between -1 and 1. Calling rng again with the same seed will produce the same random numbers.

import { rng } from "gnrng"

const getRandom1 = rng("abc")
const a = getRandom1() // Random number between -1 and 1
const b = getRandom1() // Random number between -1 and 1

const getRandom2 = rng("abc") // same seed
getRandom2() === a // true
getRandom2() === b // true

const getRandom3 = rng("xyz") // different seed
getRandom3() === a // false
getRandom3() === b // false

FAQs

Package last updated on 09 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts