82[[nodiscard]]
inline constexpr std::uint64_t
splitmix64(std::uint64_t x)
noexcept
84 x += 0x9e3779b97f4a7c15ull;
85 x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9ull;
86 x = (x ^ (x >> 27)) * 0x94d049bb133111ebull;
97[[nodiscard]]
inline constexpr std::uint64_t
mix_seed(
const std::uint64_t a,
98 const std::uint64_t b)
noexcept
114template <std::
size_t Rank>
117 std::uint64_t
h = 0xcbf29ce484222325ull;
118 for (std::size_t d = 0; d < Rank; ++d)
120 const std::uint64_t component =
static_cast<std::uint64_t
>(
static_cast<std::int64_t
>(c[d]));
140template <std::
size_t Rank>
141[[nodiscard]]
inline constexpr std::uint64_t
cell_seed(
const std::uint64_t master_seed,
142 const std::size_t step,
145 const std::uint64_t step_hash
146 =
splitmix64(
static_cast<std::uint64_t
>(step) + 0xa5a5a5a5a5a5a5a5ull);
147 const std::uint64_t coord_hash = cell_key_from_coord<Rank>(coord);
148 return splitmix64(master_seed ^ step_hash ^ coord_hash);
159template <std::
size_t Rank>
160[[nodiscard]]
inline constexpr std::uint64_t
cell_seed(
const std::uint64_t master_seed,
163 return cell_seed<Rank>(master_seed, ctx.step, ctx.coord);
180[[nodiscard]]
inline constexpr std::uint64_t
thread_step_seed(
const std::uint64_t master_seed,
181 const std::size_t thread_id,
182 const std::size_t step)
noexcept
184 const std::uint64_t tid_hash
185 =
splitmix64(
static_cast<std::uint64_t
>(thread_id) + 0xfeedfacecafebee0ull);
186 const std::uint64_t step_hash
187 =
splitmix64((
static_cast<std::uint64_t
>(step) << 32) ^ 0x0123456789abcdefull);
188 return splitmix64(master_seed ^ tid_hash ^ step_hash);
205template <
typename Engine>
208 static_assert(std::is_unsigned_v<typename Engine::result_type>,
209 "uniform_unit requires an unsigned result_type");
210 const std::uint64_t v =
static_cast<std::uint64_t
>(eng());
213 return static_cast<double>(v >> 11) * (1.0 / 9007199254740992.0);
230template <
typename Engine>
231[[nodiscard]]
inline std::size_t
uniform_int(Engine &eng,
const std::size_t lo,
const std::size_t hi)
236 const std::size_t span = hi - lo + 1;
237 std::size_t pick = lo +
static_cast<std::size_t
>(u *
static_cast<double>(span));
272template <
typename Engine = std::mt19937_64>
294 [[nodiscard]]
constexpr std::uint64_t
master_seed() const noexcept
311 template <std::
size_t Rank>
324 template <std::
size_t Rank>
327 return for_cell<Rank>(ctx.
step, ctx.
coord);
342 [[nodiscard]] Engine
for_thread_step(
const std::size_t thread_id,
const std::size_t step)
const
Common typedefs and tag types for the Cellular Automata module.
Master seed dispenser for stochastic CA rules.
typename Engine::result_type result_type
Result type of engine_type.
Engine for_cell(const Cell_Context< Rank > &ctx) const
Build a fresh deterministic engine from a Cell_Context.
constexpr std::uint64_t master_seed() const noexcept
Return the master seed.
Engine engine_type
Underlying engine type.
Engine for_cell(const std::size_t step, const Coord_Vec< Rank > &coord) const
Build a fresh deterministic engine for cell (step, coord).
constexpr Per_Thread_RNG(const std::uint64_t seed=0) noexcept
Build a dispenser around seed.
Engine for_thread_step(const std::size_t thread_id, const std::size_t step) const
Build an engine for a (thread, step) sub-stream.
constexpr std::uint64_t mix_seed(const std::uint64_t a, const std::uint64_t b) noexcept
Combine two 64-bit values into a single deterministic hash.
std::array< ca_index_t, N > Coord_Vec
Default coordinate vector.
constexpr std::uint64_t thread_step_seed(const std::uint64_t master_seed, const std::size_t thread_id, const std::size_t step) noexcept
Build a deterministic seed from (master, thread_id, step).
double uniform_unit(Engine &eng)
Map a 64-bit RNG output to a uniform value in [0, 1).
constexpr std::uint64_t cell_key_from_coord(const Coord_Vec< Rank > &c) noexcept
Hash a cell coordinate into a stable 64-bit key.
std::size_t uniform_int(Engine &eng, const std::size_t lo, const std::size_t hi)
Sample a uniform integer in [lo, hi] (inclusive).
constexpr std::uint64_t splitmix64(std::uint64_t x) noexcept
64-bit SplitMix hash.
constexpr std::uint64_t cell_seed(const std::uint64_t master_seed, const std::size_t step, const Coord_Vec< Rank > &coord) noexcept
Build a deterministic per-cell seed.
Main namespace for Aleph-w library functions.
Per-cell context handed to rules that need to know "where" and "when" they are firing.
std::size_t step
Index of the step that is currently being computed (0-based).
Coord_Vec< Rank > coord
Cell coordinate inside the current frame.