Changeset 26589
- Timestamp:
- 11/10/21 11:15:18 (3 years ago)
- Location:
- issm/trunk-jpl/src/c/shared/Random
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/shared/Random/randomgenerator.cpp
r26588 r26589 5 5 #include <iostream> 6 6 #include "./randomgenerator.h" 7 8 rnd_uniform_distribution::rnd_uniform_distribution()9 {/*{{{*/10 11 a = 1103515245; // BSD Formula12 c = 12345; // BSD Formula13 m = 2147483648; // BSD Formula14 _seed = 0;15 lbound = 0.0;16 ubound = 1.0;17 return;18 }19 /*}}}*/20 rnd_uniform_distribution::rnd_uniform_distribution(double lower,double upper){/*{{{*/21 22 a = 1103515245; // BSD Formula23 c = 12345; // BSD Formula24 m = 2147483648; // BSD Formula25 _seed = 0;26 lbound = 1.0;//lower;27 ubound = upper;28 return;29 }30 /*}}}*/31 rnd_uniform_distribution::~rnd_uniform_distribution(){}32 33 rnd_normal_distribution::rnd_normal_distribution(){/*{{{*/34 35 _seed = 0;36 mean = 0;37 sdev = 1.0;38 return;39 }40 /*}}}*/41 rnd_normal_distribution::rnd_normal_distribution(double m,double s){/*{{{*/42 43 _seed = 0;44 mean = m;45 sdev = s;46 return;47 }48 /*}}}*/49 rnd_normal_distribution::~rnd_normal_distribution(){} -
issm/trunk-jpl/src/c/shared/Random/randomgenerator.h
r26588 r26589 17 17 unsigned int m; 18 18 unsigned _seed; 19 double lbound;20 double ubound;19 double a1; 20 double a2; 21 21 22 22 int drnd() { return( _seed = ( a * _seed + c ) % m ); } … … 25 25 26 26 /*constructors, destructors: */ 27 rnd_uniform_distribution(); 28 rnd_uniform_distribution(double a_1,double a_2); 29 ~rnd_uniform_distribution(); 30 27 rnd_uniform_distribution() : _seed( 0 ), a( 1103515245 ), c( 12345 ), m( 2147483648 ), a1(0.0), a2(1.0) {} 28 rnd_uniform_distribution(double a_1,double a_2) : _seed( 0 ), a( 1103515245 ), c( 12345 ), m( 2147483648 ), a1(a_1), a2(a_2) {} 31 29 void seed( unsigned int s ) { _seed = s; } 32 30 unsigned int get_seed() { return _seed; } 33 double generator() { return ( ubound-lbound)*(double) drnd()/ m + lbound; }31 double generator() { return (a2-a1)*(double) drnd()/ m + a1; } 34 32 35 33 }; … … 44 42 45 43 public: 46 47 /*constructors, destructors: */ 48 rnd_normal_distribution(); 49 rnd_normal_distribution(double m,double s); 50 // 51 ~rnd_normal_distribution(); 52 44 rnd_normal_distribution() : _seed( 0 ), mean( 0), sdev(1.0) {} 45 rnd_normal_distribution(double m,double s) : _seed( 0 ), mean( m ), sdev(s) {} 53 46 void seed( unsigned int s ) { _seed = s; } 54 47 double generator()
Note:
See TracChangeset
for help on using the changeset viewer.