This is the maintained version of the PCG C++ library, hosted by the Total-Random organization. We have taken over maintenance to ensure this statistically excellent family of random number generators continues to work seamlessly on modern systems and compilers.
The original repository by Melissa O'Neill (imneme/pcg-cpp) has been a cornerstone of the C++ ecosystem but hasn't seen updates in several years. Total-Random exists to keep such vital legacy libraries alive by integrating community fixes, supporting new architectures, and fixing build breakages on modern IDEs.
- Windows ARM64 Support: Native support for MSVC on ARM64 architectures (Surface Pro, Apple Silicon via VM, etc.) using
__umulhintrinsics. - Improved MSVC Compatibility: Fixed ambiguous operator errors (
C2678) inset_streamandoperator>>. - Optimized
unxorshift: Implemented an optimized version of the inverse xorshift operation, improving performance for large integer types. - Consistent Typing: Unified integer type handling across different platforms to avoid compiler warnings and errors.
PCG is a family of simple fast space-efficient statistically good algorithms for random number generation. Unlike many common generators, it's not just "good enough" — it passes the most stringent statistical tests while being faster and smaller than most alternatives.
For full details on the theory and performance, visit the PCG-Random website.
This is a header-only library. To use it, simply add the include directory to your project's include path and:
#include "pcg_random.hpp"
// Standard 32-bit PCG generator
pcg32 rng;
// Seed it (optional, uses a fixed seed by default)
rng.seed(pcg_extras::seed_seq_from<std::random_device>{});
// Generate a number
uint32_t x = rng();- Use
pcg32for 32-bit output. - Use
pcg64for 64-bit output (now highly optimized for 64-bit systems and ARM64).
While the library itself is header-only, we provide tests and samples:
make
make testThis is the recommended way to build and integrate the library:
mkdir build
cd build
cmake ..
cmake --build .
ctest .This fork is specifically patched to support building with Visual Studio 2019/2022. You can use the CMake instructions above to generate a Visual Studio solution, or simply include the headers directly in your project.
include/— The core library (headers).sample/— Readable examples showing how to use the high-level API.test-high/— Functional and statistical tests.
We welcome bug fixes and compatibility patches. If you find an issue, especially on newer hardware or compiler versions, please open an issue or pull request in the Total-Random/pcg-cpp repository.
This code is distributed under the Apache License, Version 2.0 or the MIT License, at your option. See the header of each file for details.
Maintained with ❤️ by the Total-Random Team.