Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.
/ random Public archive

Deterministic pseudorandom number generator.

Notifications You must be signed in to change notification settings

geoffb/random

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@mousepox/random

Deterministic pseudorandom number generator based on a linear congruential generator algorithm.

API Reference

Random

Random (seed?: number)

Example:

// A new instance with a randomized seed
let random = new Random();

// A new instance with a specific seed
let seeded = new Random(1234567);

chance

chance (probability: number): number

Returns whether or not a random number falls within a given probability.

Example:

if (random.chance(0.5)) {
	// Chance succeeded, do something
}

next

next (): number

Returns the next random number.

Example:

let n = random.next();
// n = 0.8264938

reset

reset (seed?: number)

Resets the current state to a specified or randomized value.

Example:

// Reset to a new randomized value
random.reset();

// Reset to a specific value
random.reset(1234567);