pcg-cpp Documentation

repository·master·Indexed 21 days ago

https://github.com/imneme/pcg-cpp

A high-performance, C++11, include-only implementation of the PCG (Permuted Congruential Generator) family of random number generators. It provides normal generators for standard use cases and extended generators for k-dimensional equidistribution, with convenience typedefs such as pcg32 and pcg64.

Tokens
577
Snippets
2
Records
4
Agent score
24%

What's inside pcg-cpp

  1. Overview of PCG Random Number Generation

    master

    This library provides a C++11 implementation of the PCG (Permuted Congruential Generator) family of random number generators. PCG generators are designed to be fast, statistically excellent, and feature-rich.

    The library distinguishes between two types of generators:

    1. Normal generators: Standard generators suitable for most use cases.
    2. Extended generators: Provide k-dimensional equidistribution and specialized features (often referred to as 'party tricks').

    For most applications, normal generators are sufficient.

  2. Project directory structure

    master

    Understanding the repository layout:

    • include: Contains the core header pcg_random.hpp and supporting include files. This is what you need to include in your C++ projects.
    • test-high: Contains test code for the high-level API (using shorter, simplified function names).
    • sample: Contains human-readable sample code and various usage examples.
  3. How to use PCG generators in C++

    master

    You can access PCG generators in two ways, similar to the pattern used by std::mt19937 in the C++ standard library:

    1. Convenience Typedefs: The easiest way for most users. For 32-bit numbers, use pcg32. For 64-bit numbers, use pcg64.
    2. Underlying Templates: For advanced users who need to specify exact parameters, you can use the templates directly.

    Performance Tip: If you are on a 32-bit system and need 64-bit numbers, it may be faster to construct 64 bits using two calls to pcg32_k2 rather than using pcg64.

    // Example usage pattern (conceptual)
    #include "pcg_random.hpp"
    
    // Using a convenience typedef for 32-bit numbers
    pcg32 my_generator(seed);
    
    // Using a convenience typedef for 64-bit numbers
    pcg64 my_64bit_generator(seed);
  4. Build and test the PCG-cpp library

    master

    The library is include-only and written in C++11, meaning there is no compiled library to link against; you simply include the headers in your project.

    If you wish to build the provided demo programs or run the included tests on a Unix-style system (Linux, macOS), use the following commands:

    To build demo programs:

    make

    To run tests:

    make test
    make
    make test