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?
Ensure you have Node.js installed on your system. If you haven't, follow the link to download and install the latest version.
After Node.js is set up, install the required npm package using the following command:
npm install mersenne-twister
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.
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 therandom
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.