MarlinUtil  1.12.1
random.h
1 #include<math.h>
2 #include <cstdlib>
3 #include <climits>
4 //Romans class to produce random numbers
6 private:
7  float width;
8  float x1, x2, w;
9  float y[2];
10 public:
11  RandomNumberGenerator() { y[0]=0.0; y[1]=0.0;}
12  float* Gauss(const float width) {
13  //random number generation a la
14  //Dr. Everett (Skip) F. Carter Jr.
15  //http://www.taygeta.com/random/gaussian.html
16  for (int irand = 0; irand < 100; irand++){
17  do {
18  // generate pair of random numbers
19  // generate first random number
20  float frand = rand();
21  frand = frand/RAND_MAX;
22  x1 = 2.0*(frand) - 1.0;
23  // generate second random number
24  frand = rand();
25  frand = frand/RAND_MAX;
26  x2 = 2.0*frand - 1.0;
27  w = x1 *x1 + x2*x2;
28  } while ( w >= 1.0 );
29  w = sqrt( (-2.0 * log( w ) ) / w );
30  y[0] = width*x1 * w + 1.0;
31  y[1] = width*x2 * w + 1.0;
32  //cout << width << endl;
33  // random->Fill(y1);
34  // random->Fill(y2);
35  }
36  return &y[0];
37  }
38  float* EqualDistribution(const float width){
39  y[0] = -1000.;
40  //assign dummy value to y[1]
41  y[1] = -1.;
42  while ( y[0] < (1.-width) || y[0] > (1.+width) )
43  {
44  y[0] = 0.5+rand()/(RAND_MAX*1.0);
45  }
46  //cout << y[0] << endl;
47  //y[0] = width* rand()/RAND_MAX;
48  return &y[0];
49  }
50 
51 };
Definition: random.h:5