Skip to content

Chocobo1/OSRandom

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OSRandom TravisCI_badge AppVeyor_badge

C++11 header-only OS Random Layer

A header-only random layer that expose cryptographically secure pseudorandom number generators (CSPRNG) provided by OS:

Prerequisites

  • 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 sure NOMINMAX is defined before Windows.h
  • Run tests

Usage

To use this header in your project:

  1. Download osrandom.hpp

  2. 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();
    }

Run Tests

To run tests, execute:

git submodule update --init --remote --recursive

cd test

# linux
make
./run_tests

# Windows
build.bat
run_tests.exe

License

See LICENSE file

Releases

No releases published

Packages

No packages published