{
"title": "exprnd",
"category": "stats/random",
"keywords": [
"exprnd",
"exponential",
"random",
"distribution",
"statistics",
"queueing",
"poisson"
],
"summary": "Exponentially-distributed random numbers with mean mu.",
"references": [],
"gpu_support": {
"elementwise": false,
"reduction": false,
"precisions": [
"f64"
],
"broadcasting": "none",
"notes": "Uses the provider random_exponential hook (Philox CSPRNG + inverse-transform sampling) when an F64-precision provider is active. F32 providers and providers without the hook fall back to host generation."
},
"fusion": {
"elementwise": false,
"reduction": false,
"max_inputs": 0,
"constants": "none"
},
"requires_feature": null,
"tested": {
"unit": "builtins::stats::random::exprnd::tests",
"integration": null
},
"description": "`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)`.",
"behaviors": [
"`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": [
{
"description": "Single sample from Exp(2)",
"input": "rng(0);\nr = exprnd(2)"
},
{
"description": "Matrix of arrival times for a Poisson process (lambda = 2)",
"input": "rng(0);\nlambda = 2;\nintervals = exprnd(1/lambda, 1, 5)"
},
{
"description": "M/M/1 queueing simulation fragment",
"input": "rng(0);\nlambda = 2; mu_svc = 2.5; Tsim = 100;\nt = 0; arrivals = 0;\nwhile t < Tsim\n t = t + exprnd(1/lambda);\n arrivals = arrivals + 1;\nend\narrivals"
},
{
"description": "Specifying dimensions with a size vector",
"input": "rng(0);\nT = exprnd(1, [2 3])"
}
],
"faqs": [
{
"question": "What is the relationship between mu and lambda?",
"answer": "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)`."
},
{
"question": "What is the workaround if exprnd is unavailable?",
"answer": "`exprnd(mu)` is mathematically equivalent to `-mu * log(rand())`. You can substitute `-log(rand())/lambda` inline until `exprnd` is available."
},
{
"question": "Why must mu be positive?",
"answer": "A non-positive mean is undefined for the exponential distribution. `exprnd` raises an error if `mu <= 0` to catch common parameter mistakes early."
},
{
"question": "What use cases does exprnd support?",
"answer": "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."
},
{
"question": "Does exprnd fuse with other operations?",
"answer": "No. Random generation is excluded from fusion planning to preserve statistical properties."
},
{
"question": "How do I control reproducibility?",
"answer": "Use `rng` before calling `exprnd` to seed the global generator."
}
],
"links": [
{
"label": "normrnd",
"url": "./normrnd"
},
{
"label": "unifrnd",
"url": "./unifrnd"
},
{
"label": "rand",
"url": "./rand"
},
{
"label": "randn",
"url": "./randn"
},
{
"label": "rng",
"url": "./rng"
}
],
"source": {
"label": "`crates/runmat-runtime/src/builtins/stats/random/exprnd.rs`",
"url": "https://github.com/runmat-org/runmat/blob/main/crates/runmat-runtime/src/builtins/stats/random/exprnd.rs"
}
}