Skip to content

normrnd

Random samples from a normal distribution with mean mu and standard deviation sigma.

r = normrnd(mu, sigma)
r = normrnd(mu, sigma, n)
r = normrnd(mu, sigma, m, n, ...)

Returns pseudorandom values from the normal distribution N(mu, sigma²). With two arguments, returns a single scalar. With additional dimension arguments, returns an array of the requested shape.

Uses a fresh std::random_device-seeded Mersenne Twister generator on each call — this is independent of the PRNG state used by rand, randn, etc. (so calls don’t disturb the main RNG sequence).

For parameter-free standard normal samples that share the main RNG state, use randn.

normrnd(100, 15) % single sample from N(100, 225)
normrnd(0, 1, 1000, 1) % 1000 standard-normal samples
normrnd(5, 2, 3, 3) % 3×3 from N(5, 4)
  • randn — Standard-normal random numbers (mean 0, variance 1).
  • rand — Uniformly distributed random numbers in [0, 1].