Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »


3.0.3 • Public • Published


npm Build Status Coverage Status Dependency Status

Prando is a determistic pseudo-random number generator. It can be used to create a series of random numbers that can later be re-created given the same seed.

Its goals are:

  • Generate a random number sequence
  • Reproducibility via a seed
  • Fast generation

The counterpoint is that it is not trying to be cryptographically secure.

Prando is created in TypeScript for extra code strength, but can be used both in JavaScript and TypeScript. The advantage of using it in TypeScript projects is that you get the benefit of code completion ("intellisense") by default.


Prando is better suited for games and user interfaces where randomness need to be taken into account deterministically.

For example, when creating React components for a Web page with random styles, one wouldn't want to use Math.random() during the render() call, as this would cause the element's style to change on every component update. Instead, by reusing a Prando random number generator, the same sequence of random numbers can be obtained when re-rendering a component.


Prando current uses a xorshift for 32 bits based on the triplet combination (13, 17, 5) by George Marsaglia. This combination produces a random sequence of period 229-1, meaning it would take 536,870,912 iterations until the sequence repeats itself.

This can be seen in the noise map generated by calculating values in the 0..255 range for colors in a 300x300 image. No obvious patterns are visible:

Noise example

Because of the algorithm's period length, it would actually require a noise image of at least 23,170px by 23,171px for the pattern to start repeating.

For a less visual but more accurate validation, see the module's automated tests.


Install Prando as a module dependency using NPM:

npm install prando --save



// Import (JavaScript ES5)
var Prando = require('prando');
// Import (JavaScript ES6 and TypeScript)
import Prando from 'prando';

Create an instance:

// Pseudo-random (time-based) seed
let rng = new Prando();
// Specific number seed
let rng = new Prando(123);
// Specific string (checksum-based) seed
let rng = new Prando("some-id");

Then, get a number using any of the next() functions. Example:

// Between 0 (inclusive) and 1 (exclusive)
let num =;
// Between a min (inclusive) and a max (exclusive)
let num =, 10);
// Between an integer min (inclusive) and a max (inclusive)
let num = rng.nextInt(0, 100);

Full reference

new Prando(seed:number|string = undefined):Prando

Generate a new Prando pseudo-random number generator.


  • seed: A number or string seed that determines which pseudo-random number sequence will be created. Defaults to current time.


  • A new Prando instance.

next(min:number = 0, pseudoMax:number = 1):number

Generates a pseudo-random number between a lower (inclusive) and a higher (exclusive) bounds.


  • min: The minimum number that can be randomly generated.
  • pseudoMax: The maximum number that can be randomly generated (exclusive).


  • The generated pseudo-random number.

nextInt(min:number = 10, max:number = 100):number

Generates a pseudo-random integer number in a range (inclusive).


  • min: The minimum number that can be randomly generated.
  • max: The maximum number that can be randomly generated.


  • The generated pseudo-random number.

nextString(length:number = 16, chars:string = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"):string

Generates a pseudo-random string sequence of a particular length from a specific character range.

Note: keep in mind that creating a random string sequence does not guarantee uniqueness; there is always a 1 in charLengthstringLength chance of collision. For real unique string ids, always check for pre-existing ids, or employ a robust GUID/UUID generator.

  • length: Length of the string to be generated.
  • chars: Characters that are used when creating the random string. Defaults to all alphanumeric chars (A-Z, a-z, 0-9).


  • The generated string sequence.

nextChar(chars:string = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"):string

Generates a pseudo-random string of 1 character specific character range.


  • chars: Characters that are used when creating the random string. Defaults to all alphanumeric chars (A-Z, a-z, 0-9).


  • The generated character.


Picks a pseudo-random item from an array. The array is left unmodified.

Note: keep in mind that while the returned item will be random enough, picking one item from the array at a time does not guarantee nor imply that a sequence of random non-repeating items will be picked. If you want to pick items in a random order from an array, instead of pick one random item from an array, it's best to apply a shuffle transformation to the array instead, then read it linearly.


  • array: Array of any type containing one or more candidates for random picking.


  • An item from the array.


Generates a pseudo-random boolean.


  • A value of true or false.


Reset the pseudo-random number sequence back to its starting seed. Further calls to next() will then produce the same sequence of numbers it had produced before. This is equivalent to creating a new Prando instance with the same seed as another Prando instance.


let rng = new Prando(12345678);
console.log(; // 0.6177754114889017
console.log(; // 0.5784605181725837
console.log(; // 0.6177754114889017 again
console.log(; // 0.5784605181725837 again

skip(iterations:number = 1):void

Skips ahead in the sequence of numbers that are being generated. This is equivalent to calling next() a specified number of times, but faster since it doesn't need to map the new random numbers to a range and return it.


  • iterations: The number of items to skip ahead.




npm i prando

Downloadsweekly downloads









last publish


  • avatar