/*!\file: random * \brief random number generating functions */ /*Headers*/ /*{{{*/ #include #include #include #include /* DBL_EPSILON */ #include #include #include #include #include "../Matrix/matrix.h" #include "../Exceptions/exceptions.h" #include "../MemOps/MemOps.h" #include "../io/io.h" /*}}}*/ void univariateNormal(IssmPDouble* prand, IssmPDouble mean, IssmPDouble sdev, int seedfixed=-1) { /*{{{*/ unsigned seed; /*Random seed using time_since_epoch*/ if(seedfixed==-1) seed = std::chrono::steady_clock::now().time_since_epoch().count(); /*Seed fixed by input argument*/ else seed = seedfixed; std::default_random_engine generator(seed); /*Normal Probability Distribution*/ std::normal_distribution normdistri(mean,sdev); *prand = normdistri(generator); } /*}}}*/ void multivariateNormal(IssmDouble** prand, int dim, IssmDouble mean, IssmDouble* covariancematrix, int seedfixed=-1) { /*{{{*/ IssmPDouble* sampleStandardNormal = xNew(dim); IssmDouble* sampleMultivariateNormal = xNew(dim); IssmDouble* Lchol = xNewZeroInit(dim*dim); /*True randomness if seedfixed==-1, otherwise random seed is fixed at seedfixed*/ for(int i=0;i(sampleStandardNormal); xDelete(Lchol); } /*}}}*/ void multivariateNormal(IssmDouble** prand, int dim, IssmDouble* mean, IssmDouble* covariancematrix, int seedfixed=-1) { /*{{{*/ IssmPDouble* sampleStandardNormal = xNew(dim); IssmDouble* sampleMultivariateNormal = xNew(dim); IssmDouble* Lchol = xNewZeroInit(dim*dim); /*True randomness if seedfixed==-1, otherwise random seed is fixed at seedfixed*/ for(int i=0;i(sampleStandardNormal); xDelete(Lchol); } /*}}}*/