random_unuran.h
Go to the documentation of this file.
1 /*
2  @copyright Russell Standish 2000-2013
3  @author Russell Standish
4  This file is part of EcoLab
5 
6  Open source licensed under the MIT license. See LICENSE for details.
7 */
8 
13 #include <unuran.h>
14 
15 /* dummy declaration to force classdesc to generate a dummy definition */
16 struct unur_gen;
17 
18 namespace ecolab
19 {
22  class urand: public random_gen
23  {
24  UNUR_URNG *gen;
25  friend class gaussrand;
26  friend class unuran;
27  void operator=(const urand&);
28  urand(const urand&);
29  CLASSDESC_ACCESS(urand);
30  public:
31  urand();
32  ~urand();
33  void seed(int s) {unur_urng_seed(gen,s);}
34  void Seed(int s) {seed(s);} // for backwards compatibility
35  double rand() {return unur_urng_sample(gen);};
36  // for backwards compatibility
37  void Set_gen(const char* descr) {set_gen(descr);}
40  void set_gen(const char* descr);
41  };
42 
44  class unuran: public random_gen
45  {
46  UNUR_GEN *gen;
47  void operator=(unuran&);
49  public:
50  urand uni;
51  /* specify a random generator according to unuran's string interface */
52  void set_gen(TCL_args args) {Set_gen(args);}
53  UNUR_GEN *get_gen() {return gen;}
54  void Set_gen(const char *descr)
55  {
56  if (gen) unur_free(gen);
57  gen=unur_str2gen(descr);
58  if (gen==NULL) throw error("Cannot create generator %s",descr);
59  unur_chg_urng(gen,uni.gen);
60  }
61  unuran(): gen(NULL) {}
62  unuran(const char* descr): gen(NULL) {Set_gen(descr);}
63  ~unuran() {if (gen) unur_free(gen);}
64  double rand();
65  };
66 
68  class gaussrand: public unuran
69  {
70  public:
71  gaussrand(): unuran("normal()") {}
72  };
73 
74 }
75 
76 #ifdef _CLASSDESC
77 #pragma omit pack ecolab::urand
78 #pragma omit unpack ecolab::urand
79 #pragma omit pack ecolab::unuran
80 #pragma omit unpack ecolab::unuran
81 #endif
82 
83 namespace classdesc_access
84 {
85  namespace cd=classdesc;
86  /* don't attempt to send these objects over the wire ! */
87  template <> struct access_pack<UNUR_GEN *>:
89  template <> struct access_unpack<UNUR_GEN *>:
91 
92 
93  template <> struct access_pack<ecolab::urand>:
94  public cd::NullDescriptor<cd::pack_t> {};
95  template <> struct access_unpack<ecolab::urand>:
96  public cd::NullDescriptor<cd::unpack_t> {};
97 
98  template <> struct access_pack<ecolab::unuran>:
99  public cd::NullDescriptor<cd::pack_t> {};
100  template <> struct access_unpack<ecolab::unuran>:
101  public cd::NullDescriptor<cd::unpack_t> {};
102 }
EcoLab exception class.
Definition: error.h:25
abstract base class for representing random number generators
Definition: random.h:32
Gaussian (normal) random generator.
Definition: random_basic.h:19
class to allow access to private members
Definition: classdesc_access.h:21
class to allow access to private members
Definition: classdesc_access.h:22
#define CLASSDESC_ACCESS(type)
add friend statements for each accessor function
Definition: classdesc_access.h:36
Represent arguments to TCL commands.
Definition: TCL_obj_base.h:138
universal non-uniform random generator
Definition: random_unuran.h:44
Contains definitions related to classdesc functionality.
Definition: arrays.h:2514
_OPENMP
Definition: accessor.h:16
Contains access_* structs, and nothing else. These structs are used to gain access to private members...
Definition: accessor.h:55
Definition: random_basic.h:11