ROOT  6.06/09
Reference Guide
MixMaxEngine.cxx
Go to the documentation of this file.
1 // @(#)root/mathcore:$Id$
2 // Authors: L. Moneta 8/2015
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2015 , ROOT MathLib Team *
7  * *
8  * *
9  **********************************************************************/
10 
11 // implementation file of MixMax engine
12 //
13 //
14 // Created by: Lorenzo Moneta : Tue 4 Aug 2015
15 //
16 //
17 #include "Math/MixMaxEngine.h"
18 
19 #include "mixmax.h"
20 
21 
22 namespace ROOT {
23 namespace Math {
24 
25  MixMaxEngine::MixMaxEngine(uint64_t seed) {
26  fRngState = rng_alloc();
27  SetSeed64(seed);
28  }
29 
32  }
33 
34 
35  // void MixMaxEngine::SeedUniqueStream(unsigned int clusterID, unsigned int machineID, unsigned int runID, unsigned int streamID) {
36  // seed_uniquestream(fRngState, clusterID, machineID, runID, streamID);
37  // }
38 
39  /// set decimation number
41  set_skip_number(nskip);
42  }
43 
44  /// set initial number to be used in the vector (the previous elements are skipped and not returned)
47  }
48 
49 
50  void MixMaxEngine::SetSeed(unsigned int seed) {
51  seed_spbox(fRngState, seed);
52  // no need to call iterate. The iteration will happen anyway
53  }
54 
55  void MixMaxEngine::SetSeed64(uint64_t seed) {
56  seed_spbox(fRngState, seed);
57  }
58 
59  // unsigned int MixMaxEngine::GetSeed() const {
60  // return get_next(fRngState);
61  // }
62 
63 
64  // generate one random number in interval ]0,1]
66  return get_next_float(fRngState);
67  }
68 
69  // generate one integer number
70  uint64_t MixMaxEngine::IntRndm() {
71  return get_next(fRngState);
72  }
73 
74 
75  void MixMaxEngine::RndmArray(int n, double *array){
76  // Return an array of n random numbers uniformly distributed in ]0,1]
77  fill_array(fRngState, n, array);
78  }
79 
80  void MixMaxEngine::SetState(const std::vector<StateInt_t> & state, bool warmup) {
82  fRngState = rng_copy(const_cast<StateInt_t*>(state.data()) );
83  if (warmup) iterate(fRngState);
84  }
85 
86  void MixMaxEngine::GetState(std::vector<StateInt_t> & state) const {
87  int n = rng_get_N();
88  state.resize(n);
89  for (int i = 0; i < n; ++i)
90  state[i] = fRngState->V[i];
91  }
92 
94  return rng_get_N();
95  }
96 
97  int MixMaxEngine::Counter() const {
98  return fRngState->counter;
99  }
100 
101  void MixMaxEngine::SetCounter(int val) {
102  fRngState->counter = val;
103  }
104 
105  // void MixMaxEngine::SetSpecialNumber(uint64_t /* val */ ) {
106  // //set_special_number(val);
107  // }
108 
109 
110 
111 
112  } // namespace Math
113 } // namespace ROOT
static void SetSkipNumber(int nskip)
set the number we want to use to skip generation higher value means higher luxury but slower ...
rng_state_t * rng_copy(myuint *Y)
Definition: mixmax.cxx:218
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
myuint V[N]
Definition: mixmax.h:61
void set_skip_number(int n)
Definition: mixmax.cxx:43
int rng_free(rng_state_t *X)
Definition: mixmax.cxx:212
rng_state_t * rng_alloc()
Definition: mixmax.cxx:204
static void SetFirstReturnElement(int index)
set initial number to be used in the vector.
double get_next_float(rng_state_t *X)
Definition: mixmax.cxx:120
void SetState(const std::vector< StateInt_t > &state, bool warmup=true)
set the full initial generator state and warm up generator by doing some iterations ...
void set_first_return_element(int n)
Definition: mixmax.cxx:46
void SetSeed64(uint64_t seed)
set the generator seed using a 64 bits integer
void SetSeed(unsigned int seed)
set the generator seed
myuint get_next(rng_state_t *X)
Definition: mixmax.cxx:102
int counter
Definition: mixmax.h:63
void GetState(std::vector< StateInt_t > &state) const
get the state of the generator
void RndmArray(int n, double *array)
generate an array of random numbers
void seed_spbox(rng_state_t *X, myuint seed)
Definition: mixmax.cxx:255
int nskip
Definition: mixmax.cxx:39
uint64_t IntRndm()
generate a 64 bit integer number
Namespace for new Math classes and functions.
int Counter() const
Get the counter (between 0 and Size-1)
int rng_get_N(void)
Definition: mixmax.cxx:290
void SetCounter(int val)
set the counter
double Rndm_impl()
implementation function to generrate the random number
MixMaxEngine(uint64_t seed=1)
int iterate(rng_state_t *X)
Definition: mixmax.cxx:57
static int Size()
Get the size of the generator.
const Int_t n
Definition: legend1.C:16
void fill_array(rng_state_t *X, unsigned int n, double *array)
Definition: mixmax.cxx:141