TS++ library: time series library
random.cc
Go to the documentation of this file.
1 
36 #define TS_RANDOM_CC_VERSION \
37  "TS_RANDOM_CC V1.1"
38 
39 #include <tsxx/random.h>
40 #include <gsl/gsl_rng.h>
41 #include <gsl/gsl_randist.h>
42 #include <time.h>
43 
44 namespace ts {
45 
46  namespace rnd {
47 
48  namespace helper {
49 
51  class GSLrng {
52  public:
53  explicit GSLrng(const gsl_rng_type* T)
54  {
55  gsl_rng_env_setup();
56  MR=gsl_rng_alloc(T);
57  this->seed();
58  }
59  ~GSLrng() { gsl_rng_free(MR); }
60  double ugaussian() const { return gsl_ran_ugaussian(MR); }
61  void seed(const unsigned long int& seedvalue) const
62  { gsl_rng_set(MR, seedvalue); }
63  void seed() const { this->seed(time(0)); }
64  private:
65  gsl_rng* MR;
66  }; // class GSLrng
67 
68  } // namespace helper
69 
70 /* ---------------------------------------------------------------------- */
71 
72  Tdseries dugauss(const int& n)
73  {
74  static helper::GSLrng rng(gsl_rng_default);
75  Tdseries retval(n);
76  for (int i=retval.f(); i<=retval.l(); ++i)
77  { retval(i)=rng.ugaussian(); }
78  return (retval);
79  } // Tdseries dugauss
80 
81  } // namespace rnd
82 
83 } // namespace ts
84 
85 /* ----- END OF random.cc ----- */
Tdseries dugauss(const int &n)
return gaussian uniform noise (standard dev=1, zero mean)
Definition: random.cc:72
GSLrng(const gsl_rng_type *T)
Definition: random.cc:53
void seed(const unsigned long int &seedvalue) const
Definition: random.cc:61
All stuff in this library will be placed within namespace ts.
Definition: anyfilter.cc:43
internal class used for static variable in dugauss
Definition: random.cc:51
aff::Series< double > Tdseries
Definition: random.h:50
create a random series (prototypes)
void seed() const
Definition: random.cc:63
double ugaussian() const
Definition: random.cc:60