Ignore:
Timestamp:
11/09/21 12:50:43 (3 years ago)
Author:
bulthuis
Message:

BUG: Try to fix bugs on tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/shared/Random/randomgenerator.cpp

    r26576 r26577  
    66#include "./randomgenerator.h"
    77
    8 class uniform_distribution
    9 {
     8#undef M_PI
     9#define M_PI 3.141592653589793238462643
    1010
    11 };
    1211
    13 class normal_distribution
    14 {
     12uniform_distribution_rnd::uniform_distribution_rnd(){/*{{{*/
    1513
    16 };
     14                a   = 1103515245;       // BSD Formula
     15                c  = 12345;                                     // BSD Formula
     16                m = 2147483648;                 // BSD Formula
     17                _seed = 0;
     18                lbound = 0.0;
     19                ubound = 1.0;
     20                return;
     21}
     22        /*}}}*/
     23uniform_distribution_rnd::uniform_distribution_rnd(double lower,double upper){/*{{{*/
     24
     25                a   = 1103515245;               // BSD Formula
     26                c  = 12345;                                     // BSD Formula
     27                m = 2147483648;                 // BSD Formula
     28                _seed = 0;
     29                lbound = lower;
     30                ubound = upper;
     31                return;
     32}
     33        /*}}}*/
     34uniform_distribution_rnd::~uniform_distribution_rnd(){}
     35void uniform_distribution_rnd::seed( unsigned int s ) { _seed = s; }
     36unsigned int uniform_distribution_rnd::get_seed() { return _seed; }
     37double uniform_distribution_rnd::generator() {
     38                _seed = ( a * _seed + c ) % m ;
     39                return (ubound-lbound)*(double) _seed/ m + lbound;
     40}
     41
     42
     43normal_distribution_rnd::normal_distribution_rnd(){/*{{{*/
     44
     45                _seed = 0;
     46                mean   = 0;
     47                sdev  = 1.0;
     48                return;
     49}
     50/*}}}*/
     51normal_distribution_rnd::normal_distribution_rnd(double m,double s){/*{{{*/
     52
     53                _seed = 0;
     54                mean   = m;
     55                sdev  = s;
     56                return;
     57}
     58        /*}}}*/
     59normal_distribution_rnd::~normal_distribution_rnd(){}
     60void normal_distribution_rnd::seed( unsigned int s ) { _seed = s; }
     61double normal_distribution_rnd::generator(){/*{{{*/
     62
     63                uniform_distribution_rnd unifdistri;
     64                unifdistri.seed(_seed);
     65
     66                double u1 = unifdistri.generator();
     67                double u2 = unifdistri.generator();
     68
     69                double R = sqrt(-2*log(u1));
     70                double theta = 2*M_PI*u2;
     71
     72                seed(unifdistri.get_seed());
     73
     74                return mean + sdev * (R*cos(theta));
     75
     76        }
     77        /*}}}*/
Note: See TracChangeset for help on using the changeset viewer.