From 697e6c7dc06c2607a7c5815009744c1746bd81a0 Mon Sep 17 00:00:00 2001 From: maxc01 Date: Wed, 7 Oct 2015 16:35:02 +0800 Subject: fix windows link error, issue #154 --- packages/base/src/Internal/C/vector-aux.c | 49 +++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'packages/base') diff --git a/packages/base/src/Internal/C/vector-aux.c b/packages/base/src/Internal/C/vector-aux.c index 9dbf536..1cef27d 100644 --- a/packages/base/src/Internal/C/vector-aux.c +++ b/packages/base/src/Internal/C/vector-aux.c @@ -945,6 +945,8 @@ int vectorScan(char * file, int* n, double**pp){ /* Windows use thread-safe random See: http://stackoverflow.com/questions/143108/is-windows-rand-s-thread-safe */ +#if defined (__APPLE__) || (__FreeBSD__) + inline double urandom() { /* the probalility of matching will be theoretically p^3(in fact, it is not) p is matching probalility of random(). @@ -959,6 +961,22 @@ inline double urandom() { return (double)nrand48(state) / (double)max_random; } +#else + +#define _CRT_RAND_S +inline double urandom() { + unsigned int number; + errno_t err; + err = rand_s(&number); + if (err!=0) { + printf("something wrong\n"); + return -1; + } + return (double)number / (double)UINT_MAX; +} + +#endif + double gaussrand(int *phase, double *pV1, double *pV2, double *pS) { double V1=*pV1, V2=*pV2, S=*pS; @@ -985,6 +1003,35 @@ double gaussrand(int *phase, double *pV1, double *pV2, double *pS) } +#if defined(_WIN32) || defined(WIN32) + +int random_vector(unsigned int seed, int code, DVEC(r)) { + int phase = 0; + double V1,V2,S; + + srand(seed); + + int k; + switch (code) { + case 0: { // uniform + for (k=0; k