Socket
Book a DemoInstallSign in
Socket

sutor-random

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sutor-random

A naïve seeded PRNG implementation.

latest
Source
npmnpm
Version
1.1.2
Version published
Maintainers
1
Created
Source

Sutor-Random

Build Status

Coverage Status

A naïve seeded pseudo-random number generator for JS. This is mainly meant for testing purposes: the method used is reportedly ~2-3 times slower than Math.random().

  • Should allow for multiple independent generators (testing required).
  • Array shuffle function included (uses what will be a slow implementation, leveraging reduce)

Usage

npm install into project.

// import all functions under the `Random` namespace:
import Random from 'sutor-random'
// use like:
Random.seeded()
Random.intBetween(10, 20)
// import specific functions
import { seeded, intBetween} from 'sutor-random'
// use like:
seeded()
intBetween(10, 20)

Available functions:

Random.seeded([seed])

Returns a random value between zero and one inclusive. Functionally identical to Math.random(). If the optional seed is passed, values become predictable.

> Random.seeded(1)
0.7098480789645691

Random.intBetween(min, max[, seed])

Returns a random integer between min and max inclusive. If the optional seed is passed, values become predictable.

> Random.intBetween(10, 20, 1)
17

Random.intUpTo(max[, seed])

Returns a random integer between zero and max inclusive. If the optional seed is passed, values become predictable.

> Random.intBetween(20, 1)
14

Random.shuffle(array[, seed])

Shuffles an array randomly, using Random.seeded() + a privately-defined shuffle function. If the optional seed is passed, values become predictable.

> Random.shuffle([1,2,3,4,5,6], 20)
[2,4,6,3,1,5]

Keywords

es6

FAQs

Package last updated on 03 Jun 2016

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

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.