summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
Diffstat (limited to 'packages')
-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)