Quantum++  v1.0-rc2
A modern C++11 quantum computing library
qpp::RandomDevices Class Referencefinal

Singeleton class that manages the source of randomness in the library. More...

#include <classes/random_devices.h>

Inheritance diagram for qpp::RandomDevices:
Collaboration diagram for qpp::RandomDevices:

Public Member Functions

std::mt19937 & get_prng ()
 Returns a reference to the internal PRNG object. More...
 
std::istream & load (std::istream &is)
 Loads the state of the PRNG from an input stream. More...
 
std::ostream & save (std::ostream &os) const
 Saves the state of the PRNG to an output stream. More...
 

Private Member Functions

 RandomDevices ()
 Initializes and seeds the random number generators. More...
 
 ~RandomDevices ()=default
 Default destructor. More...
 

Private Attributes

std::random_device rd_
 used to seed std::mt19937 prng_ More...
 
std::mt19937 prng_
 Mersenne twister random number generator. More...
 

Friends

class internal::Singleton< RandomDevices >
 

Additional Inherited Members

- Static Public Member Functions inherited from qpp::internal::Singleton< RandomDevices >
static RandomDevicesget_instance () noexcept(std::is_nothrow_constructible< RandomDevices >::value)
 
static RandomDevicesget_thread_local_instance () noexcept(std::is_nothrow_constructible< RandomDevices >::value)
 
- Protected Member Functions inherited from qpp::internal::Singleton< RandomDevices >
 Singleton () noexcept=default
 
 Singleton (const Singleton &)=delete
 
Singletonoperator= (const Singleton &)=delete
 
virtual ~Singleton ()=default
 

Detailed Description

Singeleton class that manages the source of randomness in the library.

Consists of a wrapper around an std::mt19937 Mersenne twister random number generator engine and an std::random_device engine. The latter is used to seed the Mersenne twister.

Warning
This class DOES NOT seed the standard C number generator used by Eigen::Matrix::Random(), since it is not thread safe. Do not use Eigen::Matrix::Random() or functions that depend on the C style random number engine, but use qpp::rand() instead!

Constructor & Destructor Documentation

◆ RandomDevices()

qpp::RandomDevices::RandomDevices ( )
inlineprivate

Initializes and seeds the random number generators.

◆ ~RandomDevices()

qpp::RandomDevices::~RandomDevices ( )
privatedefault

Default destructor.

Member Function Documentation

◆ get_prng()

std::mt19937& qpp::RandomDevices::get_prng ( )
inline

Returns a reference to the internal PRNG object.

Returns
Reference to the internal PRNG object

◆ load()

std::istream& qpp::RandomDevices::load ( std::istream &  is)
inline

Loads the state of the PRNG from an input stream.

Parameters
isInput stream
Returns
The input stream

◆ save()

std::ostream& qpp::RandomDevices::save ( std::ostream &  os) const
inline

Saves the state of the PRNG to an output stream.

Parameters
osOutput stream
Returns
The output stream

Friends And Related Function Documentation

◆ internal::Singleton< RandomDevices >

friend class internal::Singleton< RandomDevices >
friend

Member Data Documentation

◆ prng_

std::mt19937 qpp::RandomDevices::prng_
private

Mersenne twister random number generator.

◆ rd_

std::random_device qpp::RandomDevices::rd_
private

used to seed std::mt19937 prng_


The documentation for this class was generated from the following file: