Markopy
Utilizing Markov Models for brute forcing attacks
Markov::Random::Marsaglia Class Reference

Implementation of Marsaglia Random Engine. More...

#include <random.h>

Inheritance diagram for Markov::Random::Marsaglia:
Collaboration diagram for Markov::Random::Marsaglia:

Public Member Functions

 Marsaglia ()
 Construct Marsaglia Engine. More...
 
unsigned long random ()
 Generate Random Number. More...
 

Public Attributes

unsigned long x
 
unsigned long y
 
unsigned long z
 

Protected Member Functions

std::random_device & rd ()
 Default random device for seeding. More...
 
std::default_random_engine & generator ()
 Default random engine for seeding. More...
 
std::uniform_int_distribution< long long unsigned > & distribution ()
 Distribution schema for seeding. More...
 

Detailed Description

Implementation of Marsaglia Random Engine.

This is an implementation of Marsaglia Random engine, which for most use cases is a better fit than other solutions. Very simple mathematical formula to generate pseudorandom integer, so its crazy fast.

This implementation of the Marsaglia Engine is seeded by random.h default random engine. RandomEngine is only seeded once so its not a performance issue.

Example Use: Using Marsaglia Engine with RandomWalk

Model.import("model.mdl");
char* res = new char[11];
Markov::Random::Marsaglia MarsagliaRandomEngine;
for (int i = 0; i < 10; i++) {
this->RandomWalk(&MarsagliaRandomEngine, 5, 10, res);
std::cout << res << "\n";
}
Implementation of Marsaglia Random Engine.
Definition: random.h:125

Example Use: Generating a random number with Marsaglia Engine

std::cout << me.random();
unsigned long random()
Generate Random Number.
Definition: random.h:140

Definition at line 125 of file random.h.

Constructor & Destructor Documentation

◆ Marsaglia()

Markov::Random::Marsaglia::Marsaglia ( )
inline

Construct Marsaglia Engine.

Initialize x,y and z using the default random engine.

Definition at line 132 of file random.h.

132  {
133  this->x = this->distribution()(this->generator());
134  this->y = this->distribution()(this->generator());
135  this->z = this->distribution()(this->generator());
136  //std::cout << "x: " << x << ", y: " << y << ", z: " << z << "\n";
137  }
std::uniform_int_distribution< long long unsigned > & distribution()
Distribution schema for seeding.
Definition: random.h:90
std::default_random_engine & generator()
Default random engine for seeding.
Definition: random.h:82
unsigned long x
Definition: random.h:155
unsigned long y
Definition: random.h:156
unsigned long z
Definition: random.h:157

References Markov::Random::DefaultRandomEngine::distribution(), Markov::Random::DefaultRandomEngine::generator(), x, y, and z.

Here is the call graph for this function:

Member Function Documentation

◆ distribution()

std::uniform_int_distribution<long long unsigned>& Markov::Random::DefaultRandomEngine::distribution ( )
inlineprotectedinherited

Distribution schema for seeding.

Definition at line 90 of file random.h.

90  {
91  static std::uniform_int_distribution<long long unsigned> _distribution(0, 0xffffFFFF);
92  return _distribution;
93  }

Referenced by Marsaglia(), and Markov::Random::DefaultRandomEngine::random().

Here is the caller graph for this function:

◆ generator()

std::default_random_engine& Markov::Random::DefaultRandomEngine::generator ( )
inlineprotectedinherited

Default random engine for seeding.

Definition at line 82 of file random.h.

82  {
83  static std::default_random_engine _generator(rd()());
84  return _generator;
85  }
std::random_device & rd()
Default random device for seeding.
Definition: random.h:74

References Markov::Random::DefaultRandomEngine::rd().

Referenced by Marsaglia(), and Markov::Random::DefaultRandomEngine::random().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ random()

unsigned long Markov::Random::Marsaglia::random ( )
inlinevirtual

Generate Random Number.

Returns
random number in long range.

Reimplemented from Markov::Random::DefaultRandomEngine.

Definition at line 140 of file random.h.

140  {
141  unsigned long t;
142  x ^= x << 16;
143  x ^= x >> 5;
144  x ^= x << 1;
145 
146  t = x;
147  x = y;
148  y = z;
149  z = t ^ x ^ y;
150 
151  return z;
152  }

References x, y, and z.

Referenced by Markov::API::ModelMatrix::FastRandomWalkThread().

Here is the caller graph for this function:

◆ rd()

std::random_device& Markov::Random::DefaultRandomEngine::rd ( )
inlineprotectedinherited

Default random device for seeding.

Definition at line 74 of file random.h.

74  {
75  static std::random_device _rd;
76  return _rd;
77  }

Referenced by Markov::Random::DefaultRandomEngine::generator().

Here is the caller graph for this function:

Member Data Documentation

◆ x

unsigned long Markov::Random::Marsaglia::x

◆ y

unsigned long Markov::Random::Marsaglia::y

◆ z

unsigned long Markov::Random::Marsaglia::z

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