source: issm/trunk-jpl/src/c/shared/Random/randomgenerator.h@ 26576

Last change on this file since 26576 was 26576, checked in by bulthuis, 3 years ago

BUG: Try to fix bugs on tests

  • Property svn:executable set to *
File size: 1.1 KB
Line 
1/*!\file: randomgenerator.h
2 * \brief prototypes for randomgenerator.h
3 */
4
5#ifndef _RANDOMGENERATOR_H_
6#define _RANDOMGENERATOR_H_
7
8#undef M_PI
9#define M_PI 3.141592653589793238462643
10
11class uniform_distribution_rnd
12{
13
14 private:
15
16 unsigned int a;
17 unsigned int c;
18 unsigned int m;
19 unsigned _seed;
20 double a1;
21 double a2;
22
23 int drnd() { return( _seed = ( a * _seed + c ) % m ); }
24
25 public:
26
27 /*constructors, destructors: */
28 uniform_distribution_rnd();
29 uniform_distribution_rnd(double a_1, double a_2);
30 ~uniform_distribution_rnd();
31
32 void seed( unsigned int s ) { _seed = s; }
33 unsigned int get_seed() { return _seed; }
34 double rnd() { return (a2-a1)*(double) drnd()/ m + a1; }
35
36};
37
38class normal_distribution_rnd
39{
40
41 private:
42 unsigned _seed;
43 double mean;
44 double sdev;
45
46 public:
47 normal_distribution_rnd() : _seed( 0 ), mean( 0), sdev(1.0) {}
48 normal_distribution_rnd(double m,double s) : _seed( 0 ), mean( m ), sdev(s) {}
49 void seed( unsigned int s ) { _seed = s; }
50 double rnd();
51
52};
53
54#endif //ifndef _RANDOMGENERATOR_H_
Note: See TracBrowser for help on using the repository browser.