openModeller  Version 1.5.0
Random.cpp
Go to the documentation of this file.
1 
29 #include <openmodeller/Random.hh>
31 
32 #include <stdlib.h>
33 
34 
35 /********************************************************/
36 /************************ Random ************************/
37 
38 int Random::_initialized = 0;
39 
40 
41 /*******************/
42 /*** Constructor ***/
43 
45 {
46  if ( ! _initialized )
48 }
49 
50 
51 /********************/
52 /*** get (double) ***/
53 double
54 Random::get( double min, double max )
55 {
56  return( (max-min) * random() + min );
57 }
58 
59 double
60 Random::get( double max )
61 {
62  return( max * random() );
63 }
64 
65 
66 /***************************/
67 /*** operator() (double) ***/
68 double
69 Random::operator()( double min, double max )
70 {
71  return( (max-min) * random() + min );
72 }
73 
74 double
75 Random::operator()( double max )
76 {
77  return( max * random() );
78 }
79 
80 
81 /*****************/
82 /*** get (int) ***/
83 int
84 Random::get( int min, int max )
85 {
86  return( int((max-min) * random()) + min );
87 }
88 
89 int
90 Random::get( int max )
91 {
92  return( int(max * random()) );
93 }
94 
95 
96 /************************/
97 /*** operator() (int) ***/
98 int
99 Random::operator()( int min, int max )
100 {
101  return( int((max-min) * random()) + min );
102 }
103 
104 int
106 {
107  return( int(max * random()) );
108 }
109 
110 
111 /*******************/
112 /*** get (long) ***/
113 long
114 Random::get( long min, long max )
115 {
116  return( long((max-min) * random()) + min );
117 }
118 
119 long
120 Random::get( long max )
121 {
122  return( long(max * random()) );
123 }
124 
125 
126 /**************************/
127 /*** operator() (long) ***/
128 long
129 Random::operator()( long min, long max )
130 {
131  return( long((max-min) * random()) + min );
132 }
133 
134 long
136 {
137  return( long(max * random()) );
138 }
139 
140 
141 /****************/
142 /*** discrete ***/
143 double
144 Random::discrete( float range, float dim_interv )
145 {
146  double d = 2.0 * range / dim_interv;
147  int k = int( (d + 1) * random() );
148  return( k * dim_interv - range );
149 }
150 
151 
152 /**************/
153 /*** random ***/
154 double
156 {
157  return ::rand() / (RAND_MAX + 1.0);
158 }
159 
160 
int initRandom(unsigned int new_seed)
Random()
Definition: Random.cpp:44
double get()
Definition: Random.hh:54
double discrete(float range, float dim_interv)
Definition: Random.cpp:144
double operator()()
Definition: Random.hh:58
static int _initialized
Definition: Random.hh:88
double random()
Definition: Random.cpp:155
int min(int v1, int v2)
Definition: rules_base.cpp:56