source:
issm/oecreview/Archive/25834-26739/ISSM-26586-26587.diff@
26740
Last change on this file since 26740 was 26740, checked in by , 3 years ago | |
---|---|
File size: 2.8 KB |
-
../trunk-jpl/src/c/shared/Random/randomgenerator.cpp
4 4 5 5 #include <iostream> 6 6 #include "./randomgenerator.h" 7 8 rnd_uniform_distribution::rnd_uniform_distribution() 9 {/*{{{*/ 10 11 a = 1103515245; // BSD Formula 12 c = 12345; // BSD Formula 13 m = 2147483648; // BSD Formula 14 _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 Formula 23 c = 12345; // BSD Formula 24 m = 2147483648; // BSD Formula 25 _seed = 0; 26 lbound = 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(){} -
../trunk-jpl/src/c/shared/Random/randomgenerator.h
16 16 int c; 17 17 unsigned int m; 18 18 unsigned _seed; 19 double a1;20 double a2;19 double lbound; 20 double ubound; 21 21 22 22 int drnd() { return( _seed = ( a * _seed + c ) % m ); } 23 23 24 24 public: 25 rnd_uniform_distribution() : _seed( 0 ), a( 1103515245 ), c( 12345 ), m( 2147483648 ), a1(0.0), a2(1.0) {} 26 rnd_uniform_distribution(double a_1,double a_2) : _seed( 0 ), a( 1103515245 ), c( 12345 ), m( 2147483648 ), a1(a_1), a2(a_2) {} 25 26 /*constructors, destructors: */ 27 rnd_uniform_distribution(); 28 rnd_uniform_distribution(double a_1,double a_2); 29 ~rnd_uniform_distribution(); 30 27 31 void seed( unsigned int s ) { _seed = s; } 28 32 unsigned int get_seed() { return _seed; } 29 double generator() { return ( a2-a1)*(double) drnd()/ m + a1; }33 double generator() { return (ubound-lbound)*(double) drnd()/ m + lbound; } 30 34 31 35 }; 32 36 … … 39 43 double sdev; 40 44 41 45 public: 42 rnd_normal_distribution() : _seed( 0 ), mean( 0), sdev(1.0) {} 43 rnd_normal_distribution(double m,double s) : _seed( 0 ), mean( m ), sdev(s) {} 46 47 /*constructors, destructors: */ 48 rnd_normal_distribution(); 49 rnd_normal_distribution(double m,double s); 50 ~rnd_normal_distribution(); 51 44 52 void seed( unsigned int s ) { _seed = s; } 45 53 double generator() 46 54 {
Note:
See TracBrowser
for help on using the repository browser.