From e93cd3dee7ddfb7e688ed300adcfaacc5cbad7b6 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Sun, 14 Dec 2014 11:41:50 +0100 Subject: change drand48_r to random_r --- packages/base/src/C/vector-aux.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'packages/base/src/C') diff --git a/packages/base/src/C/vector-aux.c b/packages/base/src/C/vector-aux.c index f8feb37..54cc413 100644 --- a/packages/base/src/C/vector-aux.c +++ b/packages/base/src/C/vector-aux.c @@ -700,15 +700,15 @@ int saveMatrix(char * file, char * format, KDMAT(a)){ //////////////////////////////////////////////////////////////////////////////// -inline double urandom(struct drand48_data * buffer) { - double res; - drand48_r(buffer,&res); - return res; +inline double urandom(struct random_data * buffer) { + int32_t res; + random_r(buffer,&res); + return (double)res/RAND_MAX; } // http://c-faq.com/lib/gaussian.html -double gaussrand(struct drand48_data *buffer, +double gaussrand(struct random_data *buffer, int *phase, double *pV1, double *pV2, double *pS) { double V1=*pV1, V2=*pV2, S=*pS; @@ -735,8 +735,15 @@ double gaussrand(struct drand48_data *buffer, } int random_vector(unsigned int seed, int code, DVEC(r)) { - struct drand48_data buffer; - srand48_r(seed,&buffer); + struct random_data buffer; + char random_state[128]; + memset(&buffer, 0, sizeof(struct random_data)); + memset(random_state, 0, sizeof(random_state)); + + initstate_r(seed,random_state,sizeof(random_state),&buffer); + // setstate_r(random_state,&buffer); + // srandom_r(seed,&buffer); + int phase = 0; double V1,V2,S; -- cgit v1.2.3