C++11 header-only OS Random Layer
A header-only random layer that expose cryptographically secure pseudorandom number generators (CSPRNG) provided by OS:
- Linux, *nix, BSD ...
- C++11 compiler
/dev/random
is available to read
This means API will block when there are not enough entropy in system
- Windows
- C++11 compiler
- Warning:
NOMINMAX
is already defined and included before Windows.h header
I.e. If you include Windows.h before this library, make sureNOMINMAX
is defined before Windows.h
- Run tests
To use this header in your project:
-
Use it like:
#include <random> #include "osrandom.hpp" void example() { // Specify distribution of outputs std::uniform_int_distribution<> dist; // Get an instance... Chocobo1::OSRandom osRandom; // Voilà! int number = dist(osRandom); // Or you prefer accessing it directly int number2 = osRandom(); }
To run tests, execute:
git submodule update --init --remote --recursive
cd test
# linux
make
./run_tests
# Windows
build.bat
run_tests.exe
See LICENSE file