From 747d8bbaf2d6afeac9dda0775b42b6aa3dd58428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me?= Date: Thu, 2 May 2019 18:17:21 +0200 Subject: [PATCH] Fixed RAND_A_B macro. Added macros for generating random numbers using xorwow, passing the state to the macro. --- utils.hpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/utils.hpp b/utils.hpp index 73bbe90..0fb5444 100644 --- a/utils.hpp +++ b/utils.hpp @@ -41,8 +41,9 @@ std::cout << (x)[i_print_vec] << "\t"; \ std::cout << "\n";} #define PRINT_STR(x) std::cout << (x) << "\n" +#define PRINT_LINE() std::cout << __FILE__ << ':' << __LINE__ << "\n" -#define RAND_A_B(a, b) ((double(rand())/RAND_MAX)*(b-a) + a) +#define RAND_A_B(a, b) ((double(rand())/RAND_MAX)*((b)-(a)) + (a)) #define RAND_0_1() (double(rand())/RAND_MAX) #define MIN(a, b) ((a) < (b)) ? (a) : (b) @@ -114,6 +115,13 @@ std::ostream& operator<<(std::ostream& os, const C& objs) #include +#define RAND_MAX_XORWOW ((unsigned int)(4294967295)) +#define RAND_MAX_XORWOW_F (4294967295.0f) +#define RAND_MAX_XORWOW_D (4294967295.0) + +#define RAND_XORWOW_A_B(state, a, b) ((double(rand_xorwow(state))/RAND_MAX_XORWOW_D)*((b)-(a)) + (a)) +#define RAND_XORWOW_0_1(state) (double(rand_xorwow(state))/RAND_MAX_XORWOW_D) + /// Pseudo-random number generator algorithm "xorwow" from p. 5 of Marsaglia, "Xorshift RNGs". /// /// The period is 2^160-2^32 ~= 10^48 numbers.