RunMat
GitHub

unifrnd — Uniformly-distributed random numbers on the interval [a, b).

unifrnd draws pseudorandom samples from the continuous uniform distribution on the half-open interval [a, b). It is part of the Statistics and Machine Learning Toolbox family in MATLAB and Octave's statistics package. RunMat implements it by scaling base uniform variates as r = a + (b - a) * U where U ~ Uniform(0, 1).

How unifrnd works

  • unifrnd(a, b) returns a scalar double drawn from Uniform(a, b).
  • unifrnd(a, b, n) returns an n × n matrix of samples.
  • unifrnd(a, b, m, n) returns an m × n matrix of samples.
  • unifrnd(a, b, sz) accepts a size vector and returns an array with shape sz.
  • a and b must be scalar numeric values.
  • a must be less than b; unifrnd errors if a >= b.
  • All outputs are double precision regardless of input type.

Examples

Single sample from Uniform(2, 5)

rng(0);
r = unifrnd(2, 5)

Matrix of random values between -1 and 1

rng(0);
X = unifrnd(-1, 1, 2, 3)

Monte Carlo samples for uncertain input bounds

rng(0);
low = 10; high = 20;
samples = unifrnd(low, high, 1, 5)

Specifying dimensions with a size vector

rng(0);
T = unifrnd(0, 100, [2 3])

FAQ

Are the bounds inclusive?

RunMat generates samples on the half-open interval [a, b): values can be equal to a, but are always strictly less than b.

What is the workaround if unifrnd is unavailable?

unifrnd(a, b) is mathematically equivalent to a + (b - a) * rand(). For arrays, use a + (b - a) * rand(sz) with the same requested size.

Why must a be less than b?

A continuous uniform distribution needs a positive-width interval. unifrnd raises an error if a >= b to catch invalid bounds early.

What use cases does unifrnd support?

Common uses include Monte Carlo sampling, randomized initial conditions, parameter sweeps over bounded ranges, simulation inputs, and continuous random perturbations.

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

Random

exprnd · normrnd · rng

Summary

corrcoef · cov

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how unifrnd 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.