Skip to content

A modernized, community-maintained fork of pcg-cpp. Added support for Windows ARM64, MSVC fixes, and modern C++ standards.

License

Notifications You must be signed in to change notification settings

Total-Random/pcg-cpp

Repository files navigation

PCG Random Number Generation, C++ Edition

Maintenance Status CI License Version

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.

Why this fork?

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.

Key Improvements in this Fork:

  • Windows ARM64 Support: Native support for MSVC on ARM64 architectures (Surface Pro, Apple Silicon via VM, etc.) using __umulh intrinsics.
  • Improved MSVC Compatibility: Fixed ambiguous operator errors (C2678) in set_stream and operator>>.
  • 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.

About PCG

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.

Usage

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 pcg32 for 32-bit output.
  • Use pcg64 for 64-bit output (now highly optimized for 64-bit systems and ARM64).

Building Demos & Tests

While the library itself is header-only, we provide tests and samples:

Unix-style (Linux, macOS, MinGW)

make
make test

Modern CMake (All Platforms)

This is the recommended way to build and integrate the library:

mkdir build
cd build
cmake ..
cmake --build .
ctest .

Windows (MSVC)

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.

Directory Structure

  • include/ — The core library (headers).
  • sample/ — Readable examples showing how to use the high-level API.
  • test-high/ — Functional and statistical tests.

Maintenance & Contributions

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.

License

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.