exprnd — Generate exponentially distributed random samples with mean mu and MATLAB-compatible size handling.
exprnd(mu, ...) draws exponential random samples using mean parameter mu. It supports MATLAB-compatible scalar expansion and explicit output-size signatures.
Syntax
r = exprnd(mu)
r = exprnd(mu, sz)
r = exprnd(mu, sz1, sz2, ...)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
mu | Any | Yes | — | Exponential mean parameter (must be > 0). |
sz | Any | Yes | — | Size scalar or size vector argument. |
sz | Any | Variadic | — | Dimension extents for output shape. |
Returns
| Name | Type | Description |
|---|---|---|
r | NumericArray | Random sample array from exponential distribution. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:exprnd:MuMustBePositive | mu is zero or negative. | exprnd: mu must be greater than zero |
RunMat:exprnd:InvalidArgument | Input parameters or size arguments are missing or malformed. | exprnd: invalid argument |
RunMat:exprnd:Internal | Internal conversion/allocation/provider decode fails. | exprnd: internal operation failed |
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])Using exprnd with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how exprnd changes the result.
Run a small exprnd example, explain the result, then change one input and compare the output.
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 is executed, line by line, in Rust.
- View the source for exprnd in Rust on GitHub
- Learn how the RunMat 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 blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.