RunMat
GitHub

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

NameTypeRequiredDefaultDescription
muAnyYesExponential mean parameter (must be > 0).
szAnyYesSize scalar or size vector argument.
szAnyVariadicDimension extents for output shape.

Returns

NameTypeDescription
rNumericArrayRandom sample array from exponential distribution.

Errors

IdentifierWhenMessage
RunMat:exprnd:MuMustBePositivemu is zero or negative.exprnd: mu must be greater than zero
RunMat:exprnd:InvalidArgumentInput parameters or size arguments are missing or malformed.exprnd: invalid argument
RunMat:exprnd:InternalInternal conversion/allocation/provider decode fails.exprnd: internal operation failed

How exprnd works

  • exprnd(mu) returns a scalar double drawn from Exp(mu).
  • exprnd(mu, n) returns an n × n matrix of samples.
  • exprnd(mu, m, n) returns an m × n matrix of samples.
  • exprnd(mu, sz) accepts a size vector and returns an array with shape sz.
  • mu must be a positive scalar; exprnd errors if mu <= 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
arrivals

Specifying 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.

Random

normrnd · rng · unifrnd

Summary

corrcoef · cov · mode

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how exprnd is executed, line by line, in Rust.

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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.