![]() |
Cayley
Pseudo-Random Bits from Finite Groups
|
The Cayley PRNG. More...
#include <Cayley.h>
Public Member Functions | |
| CCayley (uint32_t n) | |
| Constructor. More... | |
| ~CCayley () | |
| Destructor. More... | |
| virtual void | srand (uint64_t(*rnd)(void)) |
| Seed the generator. More... | |
| CPerm | GetGenerator (int i) const |
| Get generator. More... | |
| const CPerm & | GetPerm () const |
| Get current permutation. More... | |
| const uint32_t | GetSize () const |
| Get permutation size. More... | |
Protected Member Functions | |
| void | ChooseGenerators (uint64_t(*rnd)(void)) |
| Choose generators. More... | |
| void | NextPerm () |
| Compute next permutation. More... | |
Protected Attributes | |
| uint32_t | m_nSize = 0 |
| Size of permutations. | |
| uint32_t | m_nOrder = 0 |
| Order of generators. | |
| CPowerTable | m_nPower [2] |
| Power tables for a pair of generators. | |
| CPerm * | m_pCurPerm = nullptr |
| Current permutation. | |
| uint64_t | m_nDelayLine [m_nDelay] |
| Delay line. More... | |
| int | m_nTail = 0 |
| Index of last element in delay line. | |
Static Protected Attributes | |
| static const int | m_nDelay = 32 |
| Delay size. | |
CCayley is a templated class that allows you to declare instances of Cayley that generate 8-bit, 16-bit, 32-bit, or 64-bit pseudorandom numbers (CCayley<uint8_t>, CCayley<uint16_t>, CCayley<uint32_t>, and CCayley<uint64_t>, respectively) using a symmetric group of any size permitted by the declaration of CPerm. Given access to another PRNG for initialization purposes, it will construct a pair of pseudorandom generators for the symmetric group and pseudorandom masks. It is recommended that this functionality be used during initial exploration and testing, and that a further class be derived from this one using fixed permutation size, generators, and masks that pass any test for pseudorandomness that you might prefer, such as DieHarder.
| CCayley::CCayley | ( | uint32_t | n | ) |
Construct the current permutation and set the order of the generators using the Landau table.
| n | The permutation size. |
Definition at line 39 of file Cayley.cpp.
| CCayley::~CCayley | ( | ) |
The destructor.
Definition at line 49 of file Cayley.cpp.
|
protected |
Choose a pair of pseudorandom odd permutations of maximal order that have no common fixed point. It is unlikely that a pair of random permutations will have the same fixed point but it is possible. Build tables of powers of these generators to speed up the computation.
| rnd | An external PRNG for seeding. |
Definition at line 68 of file Cayley.cpp.
| CPerm CCayley::GetGenerator | ( | int | i | ) | const |
Reader function for the generators.
| i | Generator number, either 0 or 1. |
Definition at line 57 of file Cayley.cpp.
| const CPerm & CCayley::GetPerm | ( | ) | const |
Reader function for the current permutation.
Definition at line 109 of file Cayley.cpp.
| const uint32_t CCayley::GetSize | ( | ) | const |
Reader function for the the permutation size, that is, the number of items permuted by the curret permutation and the generators.
Definition at line 117 of file Cayley.cpp.
|
protected |
Generate the next pseudo-random permutation as follows. Get the exponent \(k\) from the delay line and multiply the current permutation \(\phi\) by the current generator \(\sigma_i\) to the power \(k\).
Definition at line 128 of file Cayley.cpp.
|
virtual |
Initialize the pseudo-random number generator by choosing the generators and the initial permutation.
| rand | An external random number generator to use as a seed. |
Definition at line 101 of file Cayley.cpp.
|
protected |
1.8.15