summaryrefslogtreecommitdiff
path: root/packages/base/src/C
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2015-05-19 12:53:53 +0200
committerAlberto Ruiz <aruiz@um.es>2015-05-19 12:53:53 +0200
commit200c44737e7368373e19137042780e967d0d2a73 (patch)
tree6b96f1584d6709fb2a0f7da8c559048bf3267d1b /packages/base/src/C
parent5e845013180e8f86dd8153030d5f5ea13826497d (diff)
parent0840304af1564fa86a6006d648450372f301a6c8 (diff)
Merge pull request #124 from maxc01/master
solve uninstallablity in FreeBSD, a better urandom()
Diffstat (limited to 'packages/base/src/C')
-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)