This guide covers the random number generation utilities in Vulcan, providing reproducible and convenient RNG for sensor simulation and Monte Carlo analysis.
Quick Start
double x = rng.gaussian();
double y = rng.uniform(0.0, 10.0);
Eigen::Vector3d noise = rng.gaussian3();
Vulcan Random Number Generator.
Definition RNG.hpp:37
The RNG Class
The vulcan::rng::RNG class wraps std::mt19937_64 with convenience methods for aerospace simulation.
Design Principles
| Principle | Rationale |
| Explicit seeding | No auto-seeding ensures reproducibility |
| Cross-platform | Same seed produces identical sequence everywhere |
| Seed storage | Original seed is saved for logging/debugging |
Construction
std::seed_seq seq{1, 2, 3, 4};
- Important
- RNGs are non-copyable to prevent accidental state sharing. Use std::move() if needed.
Generating Random Numbers
Gaussian (Normal) Distribution
double x = rng.gaussian();
double y = rng.gaussian(5.0, 2.0);
Eigen::Vector3d v = rng.gaussian3();
Eigen::Vector<double, 6> w = rng.gaussianN<6>();
Uniform Distribution
double u = rng.uniform();
double u2 = rng.uniform(-5.0, 5.0);
int64_t i = rng.uniform_int(1, 100);
State Management
std::cout << "Using seed: " << rng.seed() << std::endl;
rng.reset();
rng.reseed(12345);
rng.discard(1000);
std::mt19937_64& engine = rng.engine();
Noise Generators
Higher-level functions for sensor simulation are in vulcan::rng:::
IMU Noise Generation
IMUNoiseState< Scalar > init_state()
Initialize IMU noise state.
Definition AllanVarianceNoise.hpp:139
sensors::IMUNoiseSample< Scalar > step(IMUNoiseState< Scalar > &state, const IMUNoiseCoeffs &coeffs, const IMUNoiseInput< Scalar > &input)
Step the complete IMU noise model.
Definition AllanVarianceNoise.hpp:213
IMUNoiseCoeffs consumer_grade_coeffs(double dt)
Compute coefficients for consumer-grade IMU.
Definition AllanVarianceNoise.hpp:277
allan::IMUNoiseInput< double > generate_imu_noise(RNGType &rng)
Generate IMU noise input for Allan variance model.
Definition Distributions.hpp:37
White Noise Vectors
Eigen::Vector3d generate_noise3(RNGType &rng)
Generate 3-axis white noise.
Definition Distributions.hpp:57
Eigen::Vector< double, N > generate_noiseN(RNGType &rng)
Generate N-dimensional white noise.
Definition Distributions.hpp:70
Correlated Noise
Eigen::Matrix3d P = ...;
Eigen::Matrix3d L = P.llt().matrixL();
Eigen::Vector< double, N > generate_correlated_noise(RNGType &rng, const Eigen::Matrix< double, N, N > &L)
Generate correlated noise with given Cholesky factor.
Definition Distributions.hpp:92
Turbulence Forcing
double noise_u, noise_v, noise_w;
void generate_turbulence_noise(RNGType &rng, double &noise_u, double &noise_v, double &noise_w)
Generate turbulence forcing noise (3 independent channels).
Definition Distributions.hpp:130
Seeding Utilities
Functions in vulcan::rng:: for managing seeds:
Hardware Seed
std::cout << "Random seed: " << seed << std::endl;
uint64_t hardware_seed()
Generate seed from std::random_device.
Definition Seeding.hpp:30
- Warning
- Only use hardware_seed() for initial seeding. Always log the returned value for reproducibility.
Named Seeds
uint64_t seed_from_string(std::string_view name)
Hash-based seed from string.
Definition Seeding.hpp:61
Parallel Streams
For Monte Carlo simulations with independent parallel streams:
uint64_t base_seed = 42;
int num_runs = 100;
for (int run = 0; run < num_runs; ++run) {
}
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
Seed Advancement
uint64_t advance_seed(uint64_t seed, uint64_t n)
Advance seed to skip N sequences.
Definition Seeding.hpp:101
Integration with Sensor Models
Bias Instability
for (int i = 0; i < 10000; ++i) {
bias_state, bias_coeffs, rng.gaussian()
);
}
State< Scalar > init_state()
Initialize state to zero bias.
Definition BiasInstability.hpp:34
Scalar step(State< Scalar > &state, const Coeffs &coeffs, const Scalar &noise_input)
Step the bias instability process.
Definition BiasInstability.hpp:96
Coeffs compute_coeffs(double sigma_b, double tau, double dt)
Compute bias instability coefficients.
Definition BiasInstability.hpp:73
Random Walk
for (int i = 0; i < 1000; ++i) {
}
Scalar step(State< Scalar > &state, const Coeffs &coeffs, const Scalar &noise_input)
Step the random walk process.
Definition RandomWalk.hpp:80
State< Scalar > init_state()
Initialize random walk state to zero.
Definition RandomWalk.hpp:32
Coeffs compute_coeffs(double K, double dt)
Compute random walk coefficients.
Definition RandomWalk.hpp:60
API Reference
RNG.hpp
| Method | Description |
| RNG(uint64_t seed) | Construct with integer seed |
| RNG(std::seed_seq& seq) | Construct with seed sequence |
| gaussian() | Sample from N(0, 1) |
| gaussian(mean, stddev) | Sample from N(mean, stddev²) |
| uniform() | Sample from U[0, 1) |
| uniform(min, max) | Sample from U[min, max) |
| uniform_int(min, max) | Sample integer from [min, max] |
| gaussian3() | 3D vector of N(0, 1) samples |
| gaussianN<N>() | N-dimensional vector of N(0, 1) |
| seed() | Get original seed |
| reset() | Reset to initial state |
| reseed(seed) | Reseed with new value |
| discard(n) | Skip n values |
| engine() | Access underlying MT19937_64 |
Distributions.hpp
| Function | Description |
| generate_imu_noise(rng) | 18-channel IMU noise input |
| generate_noise3(rng) | 3D white noise vector |
| generate_noiseN<N>(rng) | N-dimensional white noise |
| generate_correlated_noise<N>(rng, L) | Correlated noise with Cholesky factor |
| generate_turbulence_noise(rng, u, v, w) | 3-channel turbulence forcing |
Seeding.hpp
| Function | Description |
| hardware_seed() | Get seed from std::random_device |
| create_seed_seq({...}) | Create seed sequence from values |
| seed_from_string(name) | Deterministic seed from string |
| stream_seed(base, index) | Unique seed for parallel stream |
| advance_seed(seed, n) | Advance seed by n positions |
Example: Complete Demo
See examples/sensors/sensor_noise_demo.cpp for comprehensive usage demonstrating:
- IMU noise simulation with Allan variance
- Bias instability accumulation
- Random walk drift
- Symbolic graph generation
# Build and run the demo
./scripts/build.sh
./build/examples/sensor_noise_demo