imate
C++/CUDA Reference
SplitMix64 Class Reference

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

#include <split_mix_64.h>

Public Member Functions

 SplitMix64 (const int64_t seed_)
 Constructor. Initializes the state with current time. More...
 
uint64_t next ()
 Generates the next presudo-random number in the sequence. More...
 

Protected Attributes

uint64_t state
 

Detailed Description

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

The SplitMix64 algorithm is very fast but does not pass all statistical tests. This class is primarily used to initialize the states of the Xoshiro256StarStar class.

The SplitMix64 algorithm is develped by Sebastiano Vigna (2015) and the source code is available at: https://prng.di.unimi.it/splitmix64.c

See also
Xoshiro256StarStar

Definition at line 42 of file split_mix_64.h.

Constructor & Destructor Documentation

◆ SplitMix64()

SplitMix64::SplitMix64 ( const int64_t  seed_)
explicit

Constructor. Initializes the state with current time.

Definition at line 28 of file split_mix_64.cpp.

29 {
30  // Seed the random generating algorithm with a high resolution time counter
31  uint64_t seed;
32 
33  if (seed_ >= 0)
34  {
35  seed = static_cast<uint64_t>(seed_);
36  }
37  else
38  {
39  // Negative integer is a flag to indicate using time to generate a seed
40  seed = get_highres_time_stamp();
41  }
42 
43  // Seeding as follow only fills the first 32 bits of the 64-bit integer.
44  // Repeat the first 32 bits on the second 32-bits to create a better 64-bit
45  // random number
46  this->state = (seed << 32) | seed;
47 }
uint64_t state
Definition: split_mix_64.h:49
uint64_t get_highres_time_stamp(void)

References get_highres_time_stamp(), and state.

Here is the call graph for this function:

Member Function Documentation

◆ next()

uint64_t SplitMix64::next ( )

Generates the next presudo-random number in the sequence.

Definition at line 57 of file split_mix_64.cpp.

58 {
59  uint64_t z = (state += 0x9e3779b97f4a7c15);
60  z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9;
61  z = (z ^ (z >> 27)) * 0x94d049bb133111eb;
62 
63  return z ^ (z >> 31);
64 }

References state.

Referenced by Xoshiro256StarStar::Xoshiro256StarStar().

Here is the caller graph for this function:

Member Data Documentation

◆ state

uint64_t SplitMix64::state
protected

Definition at line 49 of file split_mix_64.h.

Referenced by next(), and SplitMix64().


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