source: issm/oecreview/Archive/25834-26739/ISSM-26586-26587.diff@ 26740

Last change on this file since 26740 was 26740, checked in by Mathieu Morlighem, 3 years ago

CHG: added 25834-26739

File size: 2.8 KB
  • ../trunk-jpl/src/c/shared/Random/randomgenerator.cpp

     
    44
    55#include <iostream>
    66#include "./randomgenerator.h"
     7
     8rnd_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/*}}}*/
     20rnd_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/*}}}*/
     31rnd_uniform_distribution::~rnd_uniform_distribution(){}
     32
     33rnd_normal_distribution::rnd_normal_distribution(){/*{{{*/
     34
     35        _seed = 0;
     36        mean   = 0;
     37        sdev  = 1.0;
     38        return;
     39}
     40/*}}}*/
     41rnd_normal_distribution::rnd_normal_distribution(double m,double s){/*{{{*/
     42
     43        _seed = 0;
     44        mean   = m;
     45        sdev  = s;
     46        return;
     47}
     48/*}}}*/
     49rnd_normal_distribution::~rnd_normal_distribution(){}
  • ../trunk-jpl/src/c/shared/Random/randomgenerator.h

     
    1616    int c;
    1717    unsigned int m;
    1818    unsigned _seed;
    19     double a1;
    20     double a2;
     19    double lbound;
     20    double ubound;
    2121
    2222    int drnd() { return( _seed = ( a * _seed + c ) % m ); }
    2323
    2424  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
    2731    void seed( unsigned int s ) { _seed = s; }
    2832    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; }
    3034
    3135};
    3236
     
    3943    double sdev;
    4044
    4145  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
    4452    void seed( unsigned int s ) { _seed = s; }
    4553    double generator()
    4654    {
Note: See TracBrowser for help on using the repository browser.