Skip to content
This repository has been archived by the owner on Aug 12, 2022. It is now read-only.
/ Sutor-Random Public archive

Small seeded javascript PRNG, for testing purposes.

License

Notifications You must be signed in to change notification settings

sutorio/Sutor-Random

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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]

About

Small seeded javascript PRNG, for testing purposes.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published