exprnd — Exponentially-distributed random numbers with mean mu.
exprnd draws pseudorandom samples from the exponential distribution with mean mu (equivalently, rate parameter lambda = 1/mu). It is part of the Statistics and Machine Learning Toolbox family in MATLAB and Octave's statistics package. RunMat implements it via inverse transform sampling: r = -mu * ln(U) where U ~ Uniform(0, 1).
How exprnd works
exprnd(mu)returns a scalar double drawn fromExp(mu).exprnd(mu, n)returns ann × nmatrix of samples.exprnd(mu, m, n)returns anm × nmatrix of samples.exprnd(mu, sz)accepts a size vector and returns an array with shapesz.mumust be a positive scalar;exprnderrors ifmu <= 0.- All outputs are double precision regardless of input type.
Examples
Single sample from Exp(2)
rng(0);
r = exprnd(2)Matrix of arrival times for a Poisson process (lambda = 2)
rng(0);
lambda = 2;
intervals = exprnd(1/lambda, 1, 5)M/M/1 queueing simulation fragment
rng(0);
lambda = 2; mu_svc = 2.5; Tsim = 100;
t = 0; arrivals = 0;
while t < Tsim
t = t + exprnd(1/lambda);
arrivals = arrivals + 1;
end
arrivalsSpecifying dimensions with a size vector
rng(0);
T = exprnd(1, [2 3])FAQ
What is the relationship between mu and lambda?
The exponential distribution can be parameterised by its mean mu or its rate lambda. They are reciprocals: mu = 1/lambda. exprnd(mu) is equivalent to exprnd(1/lambda).
What is the workaround if exprnd is unavailable?
exprnd(mu) is mathematically equivalent to -mu * log(rand()). You can substitute -log(rand())/lambda inline until exprnd is available.
Why must mu be positive?
A non-positive mean is undefined for the exponential distribution. exprnd raises an error if mu <= 0 to catch common parameter mistakes early.
What use cases does exprnd support?
Common uses include queueing theory (M/M/1, M/G/1 inter-arrival and service times), reliability engineering (time-to-failure models), Poisson process simulation, and Monte Carlo sampling.
Does exprnd fuse with other operations?
No. Random generation is excluded from fusion planning to preserve statistical properties.
How do I control reproducibility?
Use rng before calling exprnd to seed the global generator.
Related Stats functions
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how exprnd works, line by line, in Rust.
- View exprnd.rs on GitHub
- Learn how the runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code — faster, on any GPU, with no license required.
- Simulations that took hours now take minutes. RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed.
- Start running code in seconds. Open the browser sandbox or download a single binary. No license server, no IT ticket, no setup.
- A full development environment. GPU-accelerated 2D and 3D plotting, automatic versioning on every save, and a browser IDE you can share with a link.