Fixed RAND_A_B macro. Added macros for generating random numbers using xorwow, passing the state to the macro.

This commit is contained in:
Jérôme 2019-05-02 18:17:21 +02:00
parent bbf7a18b66
commit 747d8bbaf2

View file

@ -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<T,Args...>& objs)
#include <cstdint>
#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.