RunMat
  • Pricing
RunMat
GitHub
GitHub
DownloadSign InTry in Browser
DesktopRuntimeServer
RunMat

Run math blazing fast

GitHubX (Twitter)LinkedIn

Company

  • About
  • Pricing
  • Contact

Explore

  • RunMat for academia
  • RunMat vs MATLAB Online
  • Benchmarks

Get product updates and release notes from the RunMat team.

© 2026 Dystr · Made withfor the scientific community.

RunMat™ is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

LicensePrivacy
/
See all docs
Builtin Reference
    • binornd
    • bootstrp
    • datasample
    • dividerand
    • exprnd
    • gamrnd
    • lhsdesign
    • mvnrnd
    • normrnd
    • random
    • randsample
    • rng
    • trnd
    • unidrnd
    • unifrnd
    • wblrnd

unifrnd — Generate uniform random samples on interval [a, b) with MATLAB-compatible size handling.

unifrnd(a, b, ...) draws pseudorandom samples from a continuous uniform distribution over [a, b). It follows MATLAB-compatible parameter broadcasting and optional size-argument forms.

Syntax

r = unifrnd(a, b)
r = unifrnd(a, b, sz)
r = unifrnd(a, b, sz1, sz2, ...)

Inputs

NameTypeRequiredDefaultDescription
aAnyYes—Lower bound parameter.
bAnyYes—Upper bound parameter (must be > a).
szAnyYes—Size scalar or size vector argument.
szAnyVariadic—Dimension extents for output shape.

Returns

NameTypeDescription
rNumericArrayRandom sample array from uniform distribution.

Errors

IdentifierWhenMessage
RunMat:unifrnd:LowerBoundMustBeLessThanUpperBounda is greater than or equal to b.unifrnd: a must be less than b
RunMat:unifrnd:InvalidArgumentInput parameters or size arguments are missing or malformed.unifrnd: invalid argument
RunMat:unifrnd:InternalInternal conversion/allocation/provider decode fails.unifrnd: internal operation failed

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 single or double values on the compatibility surface.
  • Native typed-integer bounds are independently gated RunMat extensions and must be exactly representable before entering binary64 sampling.
  • a must be less than b; unifrnd errors if a >= b.
  • Native typed-integer size controls are a separately gated RunMat extension and are decoded exactly as structural extents.
  • The currently implemented scalar-parameter path returns double output. Complete documented single-parameter class propagation and array parameter broadcasting remain implementation gaps.

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])

Using unifrnd with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how unifrnd changes the result.

Run a small unifrnd example, explain the result, then change one input and compare the output.

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.

Related Stats functions

Random

binornd · bootstrp · datasample · dividerand · exprnd · gamrnd · lhsdesign · mvnrnd · normrnd · random · randsample · rng · trnd · unidrnd · wblrnd

Ml

bayesopt · classify · confusionmat · crossvalind · cvpartition · fitclinear · fitctree · fitlm · kmeans · knnsearch · lasso · lassoglm · linkage · lscov · mnrfit · optimizableVariable · pdist · pdist2 · perfcurve · predict · regress · ridge · squareform · test · training · tsne

Summary

binocdf · boxplot · cdf · cdfplot · chi2cdf · corr · corrcoef · corrcov · cov · cov2corr · dummyvar · ecdf · filloutliers · fitdist · geomean · grpstats · harmmean · icdf · isoutlier · kstest · kurtosis · lsline · mad · mode · nanmax · normalize · normcdf · norminv · normpdf · onehotdecode · onehotencode · pdf · prctile · quantile · refline · rmse · skewness · tabulate · tcdf · tiedrank · tinv · tpdf · ttest2 · wblinv

Hist

histc · histcounts · histcounts2

Options

statget · statset

Open-source implementation

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

  • View the source for unifrnd in Rust on GitHub
  • Learn how the RunMat runtime works
  • Found a bug? Open an issue with a minimal reproduction.

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.

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • How unifrnd works
  • Examples
  • Single sample from Uniform(2, 5)
  • Matrix of random values between -1 and 1
  • Monte Carlo samples for uncertain input bounds
  • Specifying dimensions with a size vector
  • Using unifrnd with coding agents
  • FAQ
  • Related Stats functions
  • Random
  • Ml
  • Summary
  • Hist
  • Options
  • Open-source implementation
  • About RunMat