imate
C++/CUDA Reference
Xoshiro256StarStar Class Reference

Pseudo-random integer generator. This class generates 64-bit integer using Xoshiro256** algorithm. More...

#include <xoshiro_256_star_star.h>

Public Member Functions

 Xoshiro256StarStar (const int64_t seed)
 Constructor. It initializes the state variable with random integers using splitmix64 pseudo-random generator. More...
 
 ~Xoshiro256StarStar ()
 Destructor. More...
 
uint64_t next ()
 Generates the next presudo-random number. More...
 
void jump ()
 Jump function for the generator. It is equivalent to 2^128 calls to next(); it can be used to generate 2^128 non-overlapping subsequences for parallel computations. More...
 
void long_jump ()
 Long jump function for the generator. It is equivalent to 2^192 calls to next(). It can be used to generate 2^64 starting points from each of which jump() will generate 2^64 non-overlapping subsequences for parallel distributed computations. More...
 

Static Protected Member Functions

static uint64_t rotation_left (const uint64_t x, int k)
 Rotates the bits of a 64 bit integer toward left. More...
 

Protected Attributes

uint64_t * state
 

Detailed Description

Pseudo-random integer generator. This class generates 64-bit integer using Xoshiro256** algorithm.

The Xoshiro256** algorithm has 256-bit state space, and passes all statistical tests, including the BigCrush. The state of this class is initialized using SplitMix64 random generator.

A very similar method to Xoshiro256** is Xoshiro256++ which has the very same properties and speed as the Xoshiro256**. An alternative method is Xoshiro256+, which is 15% faster, but it suffers linear dependency of the lower 4 bits. It is usually used for generating floating numbers using the upper 53 bits and discard the lower bits.

The Xoshiro256** algorithm is develped by David Blackman and Sebastiano Vigna (2018) and the source code can be found at: https://prng.di.unimi.it/xoshiro256starstar.c

See also
SplitMix64

Definition at line 49 of file xoshiro_256_star_star.h.

Constructor & Destructor Documentation

◆ Xoshiro256StarStar()

Xoshiro256StarStar::Xoshiro256StarStar ( const int64_t  seed)
explicit

Constructor. It initializes the state variable with random integers using splitmix64 pseudo-random generator.

Definition at line 33 of file xoshiro_256_star_star.cpp.

33  :
34  state(NULL)
35 {
36  // Allocate state
37  this->state = new uint64_t[4];
38 
39  // Initializing SplitMix64 random generator
40  SplitMix64 split_mix_64(seed);
41 
42  for (int i=0; i < 4; ++i)
43  {
44  this->state[i] = split_mix_64.next();
45  }
46 }
Pseudo-random integer generator. This class generates 64-bit integer using SplitMix64 algorithm.
Definition: split_mix_64.h:43

References SplitMix64::next(), and state.

Here is the call graph for this function:

◆ ~Xoshiro256StarStar()

Xoshiro256StarStar::~Xoshiro256StarStar ( )

Destructor.

Definition at line 56 of file xoshiro_256_star_star.cpp.

57 {
58  if (this->state != NULL)
59  {
60  delete[] this->state;
61  this->state = NULL;
62  }
63 }

References state.

Member Function Documentation

◆ jump()

void Xoshiro256StarStar::jump ( )

Jump function for the generator. It is equivalent to 2^128 calls to next(); it can be used to generate 2^128 non-overlapping subsequences for parallel computations.

Definition at line 100 of file xoshiro_256_star_star.cpp.

101 {
102  static const uint64_t JUMP[] = {
103  0x180ec6d33cfd0aba,
104  0xd5a61266f0c9392c,
105  0xa9582618e03fc9aa,
106  0x39abdc4529b1661c};
107 
108  uint64_t s0 = 0;
109  uint64_t s1 = 0;
110  uint64_t s2 = 0;
111  uint64_t s3 = 0;
112 
113  for (unsigned int i = 0; i < sizeof(JUMP) / sizeof(*JUMP); ++i)
114  {
115  for (int b = 0; b < 64; ++b)
116  {
117  if (JUMP[i] & UINT64_C(1) << b)
118  {
119  s0 ^= this->state[0];
120  s1 ^= this->state[1];
121  s2 ^= this->state[2];
122  s3 ^= this->state[3];
123  }
124 
125  this->next();
126  }
127  }
128 
129  this->state[0] = s0;
130  this->state[1] = s1;
131  this->state[2] = s2;
132  this->state[3] = s3;
133 }
uint64_t next()
Generates the next presudo-random number.
#define UINT64_C(c)

References next(), state, and UINT64_C.

Referenced by RandomNumberGenerator::initialize().

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

◆ long_jump()

void Xoshiro256StarStar::long_jump ( )

Long jump function for the generator. It is equivalent to 2^192 calls to next(). It can be used to generate 2^64 starting points from each of which jump() will generate 2^64 non-overlapping subsequences for parallel distributed computations.

Definition at line 145 of file xoshiro_256_star_star.cpp.

146 {
147  static const uint64_t LONG_JUMP[] = {
148  0x76e15d3efefdcbbf,
149  0xc5004e441c522fb3,
150  0x77710069854ee241,
151  0x39109bb02acbe635};
152 
153  uint64_t s0 = 0;
154  uint64_t s1 = 0;
155  uint64_t s2 = 0;
156  uint64_t s3 = 0;
157 
158  for (unsigned int i = 0; i < sizeof(LONG_JUMP) / sizeof(*LONG_JUMP); ++i)
159  {
160  for (int b = 0; b < 64; ++b)
161  {
162  if (LONG_JUMP[i] & UINT64_C(1) << b)
163  {
164  s0 ^= this->state[0];
165  s1 ^= this->state[1];
166  s2 ^= this->state[2];
167  s3 ^= this->state[3];
168  }
169 
170  this->next();
171  }
172  }
173 
174  this->state[0] = s0;
175  this->state[1] = s1;
176  this->state[2] = s2;
177  this->state[3] = s3;
178 }

References next(), state, and UINT64_C.

Here is the call graph for this function:

◆ next()

uint64_t Xoshiro256StarStar::next ( )

Generates the next presudo-random number.

Definition at line 73 of file xoshiro_256_star_star.cpp.

74 {
75  const uint64_t result = this->rotation_left(this->state[1] * 5, 7) * 9;
76 
77  const uint64_t t = this->state[1] << 17;
78 
79  this->state[2] ^= this->state[0];
80  this->state[3] ^= this->state[1];
81  this->state[1] ^= this->state[2];
82  this->state[0] ^= this->state[3];
83 
84  this->state[2] ^= t;
85 
86  this->state[3] = this->rotation_left(this->state[3], 45);
87 
88  return result;
89 }
static uint64_t rotation_left(const uint64_t x, int k)
Rotates the bits of a 64 bit integer toward left.

References rotation_left(), and state.

Referenced by jump(), long_jump(), and RandomNumberGenerator::next().

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

◆ rotation_left()

uint64_t Xoshiro256StarStar::rotation_left ( const uint64_t  x,
int  k 
)
inlinestaticprotected

Rotates the bits of a 64 bit integer toward left.

Parameters
[in]xA 64 bit integer to rotate its bits toward left.
[in]kNumber of bit places to rotate each bit of x
Returns
A 64 bit integer where each bit is k bit moved left

Definition at line 192 of file xoshiro_256_star_star.cpp.

195 {
196  return (x << k) | (x >> (64 - k));
197 }

Referenced by next().

Here is the caller graph for this function:

Member Data Documentation

◆ state

uint64_t* Xoshiro256StarStar::state
protected

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