|
6 | 6 | #include <cctype> // for toupper, isspace |
7 | 7 | #include <cmath> // for log, exp, pow, NAN, sqrt, fmod, abs |
8 | 8 | #include <cstdlib> // for rand, abs, RAND_MAX |
| 9 | +#include <cstdint> // for std::uint64_t (carbon_rich_from_seed) |
9 | 10 | #include <string> // for std::string, basic_string, operator<< |
10 | 11 | #include "const.h" // for pow2, pow1_4, pow3, pow4 |
11 | 12 | #include "enviro.h" // for eff_temp_to_spec_type, getStarType |
@@ -121,6 +122,21 @@ auto about(long double value, long double variation) -> long double { |
121 | 122 | return (value + (value * random_number(-variation, variation))); |
122 | 123 | } |
123 | 124 |
|
| 125 | +/// @brief Deterministic per-system carbon-rich (C/O>1) flag from the system seed. |
| 126 | +/// Pure splitmix64 hash -> uniform [0,1) compared to CARBON_RICH_SYSTEM_FRACTION. |
| 127 | +/// Consumes NO RandomContext draw, so it does not shift the per-system RNG stream |
| 128 | +/// (only carbon-rich systems' composition changes); integer-only hash keeps it |
| 129 | +/// byte-identical across compilers/threads. |
| 130 | +auto carbon_rich_from_seed(long sys_seed) -> bool { |
| 131 | + std::uint64_t z = static_cast<std::uint64_t>(sys_seed) + 0x9E3779B97F4A7C15ULL; |
| 132 | + z = (z ^ (z >> 30)) * 0xBF58476D1CE4E5B9ULL; |
| 133 | + z = (z ^ (z >> 27)) * 0x94D049BB133111EBULL; |
| 134 | + z = z ^ (z >> 31); |
| 135 | + // Top 53 bits -> double in [0,1). |
| 136 | + const double u = static_cast<double>(z >> 11) * (1.0 / 9007199254740992.0); |
| 137 | + return u < CARBON_RICH_SYSTEM_FRACTION; |
| 138 | +} |
| 139 | + |
124 | 140 | /// @brief |
125 | 141 | /// @param ecc_coef |
126 | 142 | /// @return |
|
0 commit comments