Skip to content

Tiny (1kb), mathematically correct, Lehmer / Park-Miller Pseudorandom Number Generator

License

Notifications You must be signed in to change notification settings

Iceman8911/Tiny-PRNG

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tiny-PRNG

Tiny-PRNG is a tiny (1kb), mathematically correct, Javascript pseudorandom number generator, using the Lehmer / Park-Miller algorithm.

Usage

// Generate a random seed
const seed = Math.floor(Math.random() * (10 ** 12)

// Initialize PRNG with seed.  The seed can be any integer.
const generator = new PRNG(seed)

// Get the next pseudorandom int between 1 and 2147483646
let valueInt = generator.next()

// Get the next pseudorandom float between 0 and 1
let valueFloat = generator.nextFloat()

// Get the next pseudorandom number between 1000 and 9999
let valueBounded = generator.nextBoundedInt(1000, 9999)

// Get the current value of the seed for persistence
const currentSeed = generator.seed

NPM / Browserify / Webpack

Install
npm i @iceman8911/tiny-prng
Import
import { PRNG } from '@iceman8911/tiny-prng'

About

Tiny (1kb), mathematically correct, Lehmer / Park-Miller Pseudorandom Number Generator

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 100.0%