Skip to content

Comparison of common statistical random number generators. It includes algorithms such as Linear Congruential Generator (LCG), Mersenne Twister, and XorShift. The code demonstrates how to use these generators to generate random numbers and provides examples in the index.js file.

earlred/CommonPRNGs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Common Pseudo-Random Number Generators: Implementations and Usage Guide

This repository hosts various popular pseudo-random number generator (PRNG) implementations. These are primarily intended for statistical use cases and are not designed for cryptographic applications. For further details on these algorithms, visit our comprehensive guide on Pseudo-Random Number Generators.

Before diving into the code, here's an insightful article to read: Are You Using These Random Number Algorithms Incorrectly?

Getting Started

Prerequisites

Ensure you have Node.js installed on your system. If you haven't, follow the link to download and install the latest version.

Dependencies

After Node.js is set up, install the required npm package using the following command:

npm install mersenne-twister

Usage

To execute the PRNG examples, open your terminal, navigate to the directory containing index.js, and run the following command:

node index.js

This command will generate and print a random number from each of the implemented algorithms: Linear Congruential Generator (LCG), Mersenne Twister, and XorShift.

Description of Algorithms

Here's a quick overview of the algorithms implemented in this repository:

  • Linear Congruential Generator (LCG): Instantiate the LCG class to use this generator. Generate the next number in the sequence by calling the next method.

  • Mersenne Twister: This algorithm creates random numbers when you instantiate it with the new keyword and call the random method.

  • XorShift: Use this PRNG by instantiating the XorShift class. Like LCG, you can generate the next random number by invoking the next method.

Note: As these generators are intended for statistical purposes and not designed for cryptographic applications, they should not be used where secure randomness is required. Always opt for a cryptographically secure algorithm for such applications.

About

Comparison of common statistical random number generators. It includes algorithms such as Linear Congruential Generator (LCG), Mersenne Twister, and XorShift. The code demonstrates how to use these generators to generate random numbers and provides examples in the index.js file.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published