Vulcan
Aerospace Engineering Utilities Built on Janus
Loading...
Searching...
No Matches
Seeding.hpp
Go to the documentation of this file.
1
8
9#pragma once
10
11#include <cstdint>
12#include <functional>
13#include <initializer_list>
14#include <random>
15#include <string_view>
16
17namespace vulcan::rng {
18
30inline uint64_t hardware_seed() {
31 std::random_device rd;
32 // Combine two 32-bit values for 64-bit seed
33 uint64_t high = static_cast<uint64_t>(rd()) << 32;
34 uint64_t low = static_cast<uint64_t>(rd());
35 return high | low;
36}
37
47inline std::seed_seq create_seed_seq(std::initializer_list<uint32_t> values) {
48 return std::seed_seq(values);
49}
50
61inline uint64_t seed_from_string(std::string_view name) {
62 return std::hash<std::string_view>{}(name);
63}
64
84inline uint64_t stream_seed(uint64_t base_seed, uint64_t stream_index) {
85 // Golden ratio constant for 64-bit
86 constexpr uint64_t PHI = 0x9E3779B97F4A7C15ULL;
87 // Combine using multiplication and XOR for good mixing
88 return base_seed ^ (stream_index * PHI);
89}
90
101inline uint64_t advance_seed(uint64_t seed, uint64_t n) {
102 // Simple linear congruential step for seed advancement
103 constexpr uint64_t A = 6364136223846793005ULL;
104 constexpr uint64_t C = 1442695040888963407ULL;
105 for (uint64_t i = 0; i < n; ++i) {
106 seed = A * seed + C;
107 }
108 return seed;
109}
110
111} // namespace vulcan::rng
Definition Distributions.hpp:14
uint64_t hardware_seed()
Generate seed from std::random_device.
Definition Seeding.hpp:30
uint64_t advance_seed(uint64_t seed, uint64_t n)
Advance seed to skip N sequences.
Definition Seeding.hpp:101
std::seed_seq create_seed_seq(std::initializer_list< uint32_t > values)
Create seed sequence from multiple values.
Definition Seeding.hpp:47
uint64_t stream_seed(uint64_t base_seed, uint64_t stream_index)
Combine base seed with stream index for parallel streams.
Definition Seeding.hpp:84
uint64_t seed_from_string(std::string_view name)
Hash-based seed from string.
Definition Seeding.hpp:61