Generating Random Numbers from Various Distributions

Resource Overview

Generating random numbers from various distributions

Detailed Documentation

In scientific computing and engineering simulations, generating random numbers conforming to specific probability distributions is a fundamental and critical task. MATLAB provides a comprehensive function library supporting random number generation for multiple common probability distributions, meeting requirements in research, signal processing, financial modeling, and other scenarios. The following introduces implementation methods for several typical distributions:

Exponential Distribution The exponential distribution is commonly used to describe time intervals between events, such as packet arrival times in communication systems. MATLAB generates these through the `exprnd` function, requiring only the specification of the mean parameter. The function syntax is straightforward: `exprnd(mu)` generates random numbers with mean `mu`, where `mu` can be a scalar, vector, or matrix defining the distribution parameters.

Gaussian Distribution (Normal Distribution) The Gaussian distribution is ubiquitous in noise analysis and statistical modeling. The `randn` function directly generates standard normal random numbers with zero mean and unit variance. For custom mean (μ) and variance (σ²), apply linear transformation: `mu + sigma*randn(...)`. This approach leverages the property that scaling and shifting standard normal variables preserves normality.

Rayleigh Distribution The Rayleigh distribution frequently models channel fading in wireless communications. The `raylrnd` function generates Rayleigh-distributed random numbers with specified scale parameters, suitable for simulating multipath signal strength. The scale parameter `b` relates to the distribution's mode through `b*sqrt(2/π)`, and the function call `raylrnd(b)` produces values where the distribution's PDF is (x/b²)exp(-x²/(2b²)).

Rice Distribution The Rice distribution describes multipath channel environments with dominant line-of-sight components. While MATLAB doesn't provide a direct function, it can be generated indirectly by combining normal distributions and Bessel functions. One implementation approach uses: `sqrt((mu + sigma*randn)^2 + (sigma*randn)^2)` where `mu` represents the noncentrality parameter and `sigma` controls the spread. The Rician K-factor is calculated as (mu²)/(2*sigma²).

These functions utilize efficient underlying algorithms like the Mersenne Twister generator, ensuring high-quality pseudorandom sequences. Users can ensure reproducibility by setting random seeds with `rng` function. For more complex custom distributions, functionality can be extended using inverse transform sampling or Markov Chain Monte Carlo methods, where the probability integral transform and Metropolis-Hastings algorithm are commonly employed.