Theoretica
A C++ numerical and automatic mathematical library
theoretica::PRNG Class Reference

A pseudorandom number generator. More...

#include <prng.h>

Public Member Functions

 PRNG (pseudorandom_function p, uint64_t seed, const std::vector< uint64_t > &s)
 Construct a PRNG with the given generating algorithm p, seed x and parameters s.
 
 PRNG (pseudorandom_function p, const std::vector< uint64_t > &s)
 Construct a PRNG with the given generating algorithm p and parameters s. More...
 
 PRNG (pseudorandom_function p, uint64_t seed)
 Construct a PRNG with the given generating algorithm and seed.
 
 PRNG (uint64_t seed)
 Construct a PRNG with the default generator and the given seed.
 
void seed (uint64_t seed)
 Seed the PRNG.
 
uint64_t next ()
 Generate a pseudorandom number.
 
uint64_t operator() ()
 Generate a pseudorandom number. More...
 
void discard (uint64_t n)
 Discard n numbers from the generator. More...
 
uint64_t last () const
 Return the last generated number.
 
void set_function (pseudorandom_function p)
 Set the generating function.
 
pseudorandom_function get_function () const
 Get the generating function.
 
void set_param (const std::vector< uint64_t > &v)
 Set the generator's parameters.
 
void set_param (unsigned int i, uint64_t value)
 Set a specific parameter by index.
 
std::vector< uint64_t > get_param () const
 Get the generator's parameters.
 
PRNGoperator>> (uint64_t &n)
 Stream the next generated number.
 

Static Public Member Functions

static PRNG linear_congruential (uint64_t seed=1)
 Returns a standard linear congruential generator. More...
 
static PRNG xoshiro (const std::vector< uint64_t > &p)
 Returns a Xoshiro256++ generator. More...
 
static PRNG xoshiro (uint64_t seed=1)
 Returns a Xoshiro256++ generator. More...
 
static PRNG splitmix64 (uint64_t seed=1)
 Returns a Splitmix64 generator. More...
 
static PRNG wyrand (uint64_t seed=1, uint64_t p1=2549536629329, uint64_t p2=136137137)
 Returns a Wyrand generator.
 
static PRNG middlesquare (uint64_t seed, uint64_t offset=765872292751861)
 Returns a Middle-square generator.
 

Detailed Description

A pseudorandom number generator.

Constructor & Destructor Documentation

◆ PRNG()

theoretica::PRNG::PRNG ( pseudorandom_function  p,
const std::vector< uint64_t > &  s 
)
inline

Construct a PRNG with the given generating algorithm p and parameters s.

The seed will be set to 1.

Member Function Documentation

◆ discard()

void theoretica::PRNG::discard ( uint64_t  n)
inline

Discard n numbers from the generator.

Equivalent to calling next() n times.

◆ linear_congruential()

static PRNG theoretica::PRNG::linear_congruential ( uint64_t  seed = 1)
inlinestatic

Returns a standard linear congruential generator.

Parameters
seedThe seed to use for the generator (defaults to 1)
Returns
A standard linear congruential PRNG object

◆ operator()()

uint64_t theoretica::PRNG::operator() ( )
inline

Generate a pseudorandom number.

See also
next()

◆ splitmix64()

static PRNG theoretica::PRNG::splitmix64 ( uint64_t  seed = 1)
inlinestatic

Returns a Splitmix64 generator.

Parameters
seedThe seed to use for the generator
Returns
A splitmix64 pseudorandom number generator

◆ xoshiro() [1/2]

static PRNG theoretica::PRNG::xoshiro ( const std::vector< uint64_t > &  p)
inlinestatic

Returns a Xoshiro256++ generator.

Parameters
pThe four state parameters
Returns
A Xoshiro256++ pseudorandom number generator

◆ xoshiro() [2/2]

static PRNG theoretica::PRNG::xoshiro ( uint64_t  seed = 1)
inlinestatic

Returns a Xoshiro256++ generator.

Parameters
seedThe seed to use for the generator
Returns
A Xoshiro256++ pseudorandom number generator

The four parameters for the Xoshiro256++ algorithm are generated using the Splitmix64 algorithm.


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