/*!\file: random * \brief random number generating functions */ /*Headers*/ /*{{{*/ #include #include #include #include /* DBL_EPSILON */ #include #include #include "../Matrix/matrix.h" #include "../Exceptions/exceptions.h" #include "../MemOps/MemOps.h" #include "../io/io.h" #include "./randomgenerator.h" /*}}}*/ void univariateNormal(IssmPDouble* prand, IssmPDouble mean, IssmPDouble sdev, int seed=-1) { /*{{{*/ /*Seed the pseudo-random number generator*/ rnd::linear_congruential_engine randomengine; randomengine.seed(seed); /*Normal distribution*/ rnd::normal_distribution distriNormal(mean,sdev); *prand = distriNormal.generator(randomengine); } /*}}}*/ void multivariateNormal(IssmDouble** prand, int dim, IssmDouble mean, IssmDouble* covariancematrix, int seed=-1) { /*{{{*/ IssmPDouble* sampleStandardNormal = xNew(dim); IssmDouble* sampleMultivariateNormal = xNew(dim); IssmDouble* Lchol = xNewZeroInit(dim*dim); /*True randomness if seed<0, otherwise random seed is fixed at seed*/ /*Seed the pseudo-random number generator, repeatedly calling univariateNormal does not ensure randomness*/ rnd::linear_congruential_engine randomengine; randomengine.seed(seed); /*Normal distribution*/ rnd::normal_distribution distriNormal(0.0,1.0); for(int i=0;i(sampleStandardNormal); xDelete(Lchol); } /*}}}*/ void multivariateNormal(IssmDouble** prand, int dim, IssmDouble* mean, IssmDouble* covariancematrix, int seed=-1) { /*{{{*/ IssmPDouble* sampleStandardNormal = xNew(dim); IssmDouble* sampleMultivariateNormal = xNew(dim); IssmDouble* Lchol = xNewZeroInit(dim*dim); /*True randomness if seed<0, otherwise random seed is fixed at seed*/ /*Seed the pseudo-random number generator, repeatedly calling univariateNormal does not ensure randomness*/ rnd::linear_congruential_engine randomengine; randomengine.seed(seed); /*Normal distribution*/ rnd::normal_distribution distriNormal(0.0,1.0); for(int i=0;i(sampleStandardNormal); xDelete(Lchol); } /*}}}*/