pcg-random

Minimal C adaptation of Melissa O'Neill's PCG Random Number Generator

Pure Nim score 15/100 · last commit 2024-08-04 · 1 stars · tests present · no docs generated

Summary

Latest Version Unknown
License Unknown
CI Status Failing
Stars 1
Forks 0
Open Issues 0
Last Commit 2024-08-04
Downloads 0
Last Indexed 2026-08-06 04:57

Installation

nimble install pcg-random
choosenim install pcg-random
git clone https://gitlab.com/arunbupathy/pcg-random

OS Compatibility

Platform Linux macOS Windows FreeBSD OpenBSD NetBSD Android iOS WASM Embedded
pcg-random - - - - - - -

README

pcg-random

A minimal C implementation of Melissa O'Neill's Permuted Congruential Generator (PCG). See her page for the complete C/C++ implementation. It uses a linear congruential generator (LCG) with a power-of-two modulus, whose output it permutes to improve the quality of randomness. It is simple in design, and yet of high quality suitable for molecular simulations. It is not the fastest generator, but is reasonably quick.

What I like about this pseudo random number generator (RNG) is that the functioning of the underlying LCG is transparent to an average user. They are extensively studied and have well understood and desirable properties when the constants are chosen properly. Further, the output function or the permutation is a simple operation that depends on the internal RNG state, but does not affect the progression of the LCG itself. This means that the desirable the state space traversal properties of the LCG are preserved, while the statistical quality of the output is improved greatly.

The 64-bit version with 128 bits of internal state is the default recommended one. The 8-bit and 16-bit variants were created for my own testing purposes only.

To install do: sudo make install

For usage see: example.c

Other good PRNGs

The PCG webpage listed above is a good resource for other good PRNGs. A particularly good and fast one is Bob Jenkins's small fast PRNG, which is my current favorite. The 32-bit version is great for use in GPU code. I've not included the code here as it is already simple and in C.