Skip to content
Snippets Groups Projects
Commit 77479d45 authored by Folkert Nobels's avatar Folkert Nobels
Browse files

Change difference between different kind of random numbers to make it robust

parent 8b553991
No related branches found
No related tags found
1 merge request!742Fix the random number generator
...@@ -30,22 +30,22 @@ ...@@ -30,22 +30,22 @@
* @brief The categories of random number generated. * @brief The categories of random number generated.
* *
* The values of the fields are carefully chose numbers * The values of the fields are carefully chose numbers
* These are values adviced by NR to use on page * the numbers are very large primes such that the IDs
* 348 in the first table. We used selected 4 numbers * will not have a prime factorization with this coefficient
* and know that they produce no correlation at all * this results in a very high period for the random number
* for the 4 different processes. * generator.
* Only change when you know what you are doing, changing * Only change when you know what you are doing, changing
* the numbers to bad values will break the random number * the numbers to bad values will break the random number
* generator. * generator.
* In case new numbers need to be added other possible * In case new numbers need to be added other possible
* numbers could be: * numbers could be:
* 4162943475, 3874257210, 2654432763 * 4947009007, 5947309451, 6977309513
*/ */
enum random_number_type { enum random_number_type {
random_number_star_formation = 0LL, //4294957665LL, random_number_star_formation = 0LL,
random_number_stellar_feedback = 3947008974LL, random_number_stellar_feedback = 3947008991LL,
random_number_stellar_enrichment = 2936881968LL, random_number_stellar_enrichment = 2936881973LL,
random_number_BH_feedback = 1640531364LL random_number_BH_feedback = 1640531371LL
}; };
/** /**
...@@ -89,7 +89,7 @@ INLINE static double random_unit_interval(const long long int id, ...@@ -89,7 +89,7 @@ INLINE static double random_unit_interval(const long long int id,
* in which we use the id part and the current time step bin. * in which we use the id part and the current time step bin.
*/ */
unsigned long long number = ti_current; unsigned long long number = ti_current;
/* Multiply with carry (MWC) */ /* Multiply with carry (MWC), (adviced variables by NR) */
number = 4294957665LL * (number & (mwc_number)) + (number >> 32); number = 4294957665LL * (number & (mwc_number)) + (number >> 32);
/* 64-bit Xorshift (adviced variables by NR) */ /* 64-bit Xorshift (adviced variables by NR) */
number ^= number << 21; number ^= number << 21;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment