summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2015-05-19 12:57:02 +0200
committerAlberto Ruiz <aruiz@um.es>2015-05-19 12:57:02 +0200
commit84c2487b8682bf0e879f9303d2943b0298d6f301 (patch)
tree1cc2c9020e652cd8f7d745ecc03eb79b7eaac085
parent9034faa533b865393c1bb40fe18b0ad49a4d9e20 (diff)
parent200c44737e7368373e19137042780e967d0d2a73 (diff)
Merge branch 'master' into develop
-rw-r--r--packages/base/src/C/vector-aux.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/packages/base/src/C/vector-aux.c b/packages/base/src/C/vector-aux.c
index 599f69e..abeba76 100644
--- a/packages/base/src/C/vector-aux.c
+++ b/packages/base/src/C/vector-aux.c
@@ -701,13 +701,26 @@ int saveMatrix(char * file, char * format, KDMAT(a)){
701 701
702//////////////////////////////////////////////////////////////////////////////// 702////////////////////////////////////////////////////////////////////////////////
703 703
704#ifdef __APPLE__ 704#if defined (__APPLE__) || (__FreeBSD__)
705 705/* FreeBSD and Mac OS X do not provide random_r(), thread safety cannot be
706#pragma message "randomVector is not thread-safe in OSX" 706 guaranteed.
707 For FreeBSD and Mac OS X, nrand48() is much better than random().
708 See: http://www.evanjones.ca/random-thread-safe.html
709*/
710#pragma message "randomVector is not thread-safe in OSX and FreeBSD"
707 711
708inline double urandom() { 712inline double urandom() {
713 /* the probalility of matching will be theoretically p^3(in fact, it is not)
714 p is matching probalility of random().
715 using the test there, only 3 matches, using random(), 13783 matches
716 */
717 unsigned short state[3];
718 state[0] = random();
719 state[1] = random();
720 state[2] = random();
721
709 const long max_random = 2147483647; // 2**31 - 1 722 const long max_random = 2147483647; // 2**31 - 1
710 return (double)random() / (double)max_random; 723 return (double)nrand48(state) / (double)max_random;
711} 724}
712 725
713double gaussrand(int *phase, double *pV1, double *pV2, double *pS) 726double gaussrand(int *phase, double *pV1, double *pV2, double *pS)