Random
SourcesThe RandomNumber block generates pseudo-random scalar numbers drawn from either a uniform or a Gaussian (normal) statistical distribution. It is widely used in control system design, signal processing, and robotics to simulate sensor measurement noise, unmodeled environmental disturbances, stochastic wind gusts, and Monte Carlo tolerance variations. The block can generate fresh random seeds on every run or utilize a fixed repeatable seed for deterministic regression testing.
Mathematical Model
The output sequence follows the chosen probability distribution:
For the Uniform distribution over interval , where is minimum and is maximum:
The expected value is and the variance is .
For the Gaussian (normal) distribution with expected value (mean) and standard deviation (stdDev):
Gaussian samples are computed via the Box-Muller transform from two independent uniform variates :
Inputs & Outputs
| Direction | ID | Label | Type | Status |
|---|---|---|---|---|
| ← Out | out |
Out | number | Output |
Parameters
| Parameters | Label | Type | Default | Description |
|---|---|---|---|---|
distribution |
Distribution | select | uniform |
|
minimum |
Minimum | number | 0 |
|
maximum |
Maximum | number | 1 |
|
mean |
Mean | number | 0 |
|
stdDev |
Std Dev | number | 1 |
|
randomSeed |
New Seed Every Run | boolean | true |
Draw a fresh seed at the start of every run, so each run gives different numbers. Switch off to repeat a run exactly with a fixed seed. |
seed |
Seed | number | 12345 |
Fixed starting point of the sequence: the same seed gives the same numbers every run. |
Usage Examples
Example 1: Additive White Gaussian Noise (AWGN) in IMU Gyroscope Measurement
In an attitude-and-heading reference system (AHRS), real rate gyroscopes suffer from wideband electronic thermal noise. Configuring distribution = gaussian, mean = 0.0, stdDev = 0.015 rad/s, and randomSeed = false with seed = 42 injects realistic, repeatable sensor noise into the pitch rate signal. Summing this noise into an Extended Kalman Filter (EKF) allows exact benchmarking of filter tuning and noise rejection.
Example 2: Stochastic Bounded Wind Turbulence on an Autonomous Drone
Simulating stochastic wind speed variations affecting quadrotor position hold. Setting distribution = uniform, minimum = -3.0 m/s, maximum = 3.0 m/s, and randomSeed = true injects unpredictable bounded gusts into the aerodynamic drag equation, testing position controller disturbance rejection under non-deterministic environmental conditions.
Remarks & Best Practices
- Deterministic Reproducibility: Setting
randomSeed = falsewith a specificseedensures identical trajectories across repeated simulation runs, automated CI/CD unit tests, and parameter optimization routines. - Evaluation Rate Across Solver Substeps: The block draws a fresh pseudo-random number at each discrete simulation step. In multi-stage ODE solvers (such as RK4 or TR-BDF2), internal solver substeps hold the sampled value constant across intermediate stages to maintain solver numerical convergence.
- Continuous White Noise Scaling: For continuous white noise modeling with spectral power density and simulation sample time , scale the discrete standard deviation parameter as .
- High-Performance WASM Engine Execution: Implemented in WebAssembly using a 64-bit linear congruential and Box-Muller algorithm, imposing near-zero computational overhead even when executing thousands of evaluations per second.
Related Components
- SignalGenerator: Deterministic periodic waveforms (sine, square, triangle, sawtooth).
- Constant: Fixed, non-fluctuating reference values.
- Sum: Combines deterministic control signals with additive stochastic noise.
- Quantizer: Simulates deterministic ADC quantization discretization steps.