g4tools  5.4.0
Public Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
tools::rtausmeui Class Reference
Inheritance diagram for tools::rtausmeui:
Inheritance graph
[legend]

Public Member Functions

 rtausmeui (unsigned int a_seed=1)
 
virtual ~rtausmeui ()
 
 rtausmeui (const rtausmeui &a_from)
 
rtausmeuioperator= (const rtausmeui &a_from)
 
void set_seed (unsigned int a_seed)
 
unsigned int seed () const
 
unsigned int shoot ()
 

Static Protected Member Functions

static unsigned int LCG (unsigned int a_n)
 
static unsigned int TAUSWORTHE (unsigned int a_s, unsigned int a_a, unsigned int a_b, unsigned int a_c, unsigned int a_d)
 

Protected Attributes

unsigned int m_seed
 
unsigned int m_seed1
 
unsigned int m_seed2
 

Detailed Description

Definition at line 36 of file rtausmeui.

Constructor & Destructor Documentation

◆ rtausmeui() [1/2]

tools::rtausmeui::rtausmeui ( unsigned int  a_seed = 1)
inline

Definition at line 41 of file rtausmeui.

41  :m_seed(0),m_seed1(0),m_seed2(0){
42 #ifdef TOOLS_MEM
43  mem::increment(s_class().c_str());
44 #endif
45  set_seed(a_seed);
46  }

◆ ~rtausmeui()

virtual tools::rtausmeui::~rtausmeui ( )
inlinevirtual

Definition at line 47 of file rtausmeui.

47  {
48 #ifdef TOOLS_MEM
49  mem::decrement(s_class().c_str());
50 #endif
51  }

◆ rtausmeui() [2/2]

tools::rtausmeui::rtausmeui ( const rtausmeui a_from)
inline

Definition at line 53 of file rtausmeui.

53  :m_seed(a_from.m_seed),m_seed1(a_from.m_seed1),m_seed2(a_from.m_seed2){
54 #ifdef TOOLS_MEM
55  mem::increment(s_class().c_str());
56 #endif
57  }

Member Function Documentation

◆ LCG()

static unsigned int tools::rtausmeui::LCG ( unsigned int  a_n)
inlinestaticprotected

Definition at line 103 of file rtausmeui.

103  {
104  return ((69069 * a_n) & 0xffffffffUL); // linear congurential generator
105  }

◆ operator=()

rtausmeui& tools::rtausmeui::operator= ( const rtausmeui a_from)
inline

Definition at line 58 of file rtausmeui.

58  {
59  m_seed = a_from.m_seed;
60  m_seed1 = a_from.m_seed1;
61  m_seed2 = a_from.m_seed2;
62  return *this;
63  }

◆ seed()

unsigned int tools::rtausmeui::seed ( ) const
inline

Definition at line 83 of file rtausmeui.

83 {return m_seed;}

◆ set_seed()

void tools::rtausmeui::set_seed ( unsigned int  a_seed)
inline

Definition at line 65 of file rtausmeui.

65  {
66  m_seed = a_seed?a_seed:1;
67 
68  // Generate m_seed[1,2] needed for the generator state using
69  // a linear congruential generator
70  // The only condition, stated at the end of the 1999 L'Ecuyer paper is that the seeds
71  // must be greater than 1,7 and 15.
72 
73  m_seed = LCG(m_seed);
74  if (m_seed < 2) m_seed += 2UL;
75  m_seed1 = LCG(m_seed);
76  if (m_seed1 < 8) m_seed1 += 8UL;
77  m_seed2 = LCG(m_seed1);
78  if (m_seed2 < 16) m_seed2 += 16UL;
79 
80  // "warm it up" by calling it 6 times
81  for (unsigned int i = 0; i < 6; ++i) shoot();
82  }

◆ shoot()

unsigned int tools::rtausmeui::shoot ( )
inline

Definition at line 85 of file rtausmeui.

85  {
86  // TausWorth generator from L'Ecuyer, uses as seed 3x32bits integers
87  // Use a mask of 0xffffffffUL to make in work on 64 bit machines
88  // Periodicity of about 10**26
89 
90  unsigned int y;
91 
92  do {
93  m_seed = TAUSWORTHE (m_seed, 13, 19, 4294967294UL, 12);
94  m_seed1 = TAUSWORTHE (m_seed1, 2, 25, 4294967288UL, 4);
95  m_seed2 = TAUSWORTHE (m_seed2, 3, 11, 4294967280UL, 17);
96 
97  y = m_seed ^ m_seed1 ^ m_seed2;
98  } while(!y);
99 
100  return y;
101  }

◆ TAUSWORTHE()

static unsigned int tools::rtausmeui::TAUSWORTHE ( unsigned int  a_s,
unsigned int  a_a,
unsigned int  a_b,
unsigned int  a_c,
unsigned int  a_d 
)
inlinestaticprotected

Definition at line 106 of file rtausmeui.

106  {
107  return (((a_s & a_c) << a_d) & 0xffffffffUL ) ^ ((((a_s << a_a) & 0xffffffffUL )^ a_s) >> a_b);
108  }

Member Data Documentation

◆ m_seed

unsigned int tools::rtausmeui::m_seed
protected

Definition at line 110 of file rtausmeui.

◆ m_seed1

unsigned int tools::rtausmeui::m_seed1
protected

Definition at line 111 of file rtausmeui.

◆ m_seed2

unsigned int tools::rtausmeui::m_seed2
protected

Definition at line 112 of file rtausmeui.


The documentation for this class was generated from the following file:
tools::rtausmeui::set_seed
void set_seed(unsigned int a_seed)
Definition: rtausmeui:65
tools::rtausmeui::m_seed
unsigned int m_seed
Definition: rtausmeui:110
tools::rtausmeui::m_seed1
unsigned int m_seed1
Definition: rtausmeui:111
tools::rtausmeui::LCG
static unsigned int LCG(unsigned int a_n)
Definition: rtausmeui:103
tools::rtausmeui::TAUSWORTHE
static unsigned int TAUSWORTHE(unsigned int a_s, unsigned int a_a, unsigned int a_b, unsigned int a_c, unsigned int a_d)
Definition: rtausmeui:106
tools::rtausmeui::m_seed2
unsigned int m_seed2
Definition: rtausmeui:112
tools::rtausmeui::shoot
unsigned int shoot()
Definition: rtausmeui:85