RunMat
GitHub

normrnd — Normally-distributed random numbers with mean mu and standard deviation sigma.

normrnd draws pseudorandom samples from the normal distribution with mean mu and standard deviation sigma. It is part of the Statistics and Machine Learning Toolbox family in MATLAB and Octave's statistics package. RunMat implements it by generating standard normal variates and scaling them as r = mu + sigma * Z where Z ~ N(0, 1).

How normrnd works

  • normrnd(mu, sigma) returns a scalar double drawn from N(mu, sigma^2).
  • normrnd(mu, sigma, n) returns an n × n matrix of samples.
  • normrnd(mu, sigma, m, n) returns an m × n matrix of samples.
  • normrnd(mu, sigma, sz) accepts a size vector and returns an array with shape sz.
  • mu and sigma must be scalar numeric values.
  • sigma must be non-negative; normrnd errors if sigma < 0.
  • All outputs are double precision regardless of input type.

Examples

Single sample from N(0, 1)

rng(0);
r = normrnd(0, 1)

Matrix of Gaussian noise with mean 10 and standard deviation 2

rng(0);
X = normrnd(10, 2, 2, 3)

Simulating normally-distributed measurement errors

rng(0);
trueValue = 100;
sigma = 0.5;
measurements = trueValue + normrnd(0, sigma, 1, 5)

Specifying dimensions with a size vector

rng(0);
T = normrnd(5, 1.5, [2 3])

FAQ

What do mu and sigma mean?

mu is the distribution mean and sigma is the standard deviation. The variance is sigma^2, so normrnd(mu, sigma) draws from N(mu, sigma^2).

What is the workaround if normrnd is unavailable?

normrnd(mu, sigma) is mathematically equivalent to mu + sigma * randn(). For arrays, use mu + sigma * randn(sz) with the same requested size.

Can sigma be zero?

Yes. sigma = 0 is allowed and returns deterministic samples equal to mu. Negative standard deviations are undefined and raise an error.

What use cases does normrnd support?

Common uses include Gaussian noise generation, measurement error simulation, confidence interval experiments, Monte Carlo sampling, and normally-distributed model residuals.

Does normrnd 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 normrnd to seed the global generator.

Random

exprnd · rng · unifrnd

Summary

corrcoef · cov

Open-source implementation

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

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.

Getting started · Benchmarks · Pricing

Try RunMat for free

Open the sandbox and start running MATLAB code in seconds. No account required.