RunMat
  • Pricing
RunMat
GitHub
GitHub
Sign inTry in browser
DesktopRuntimePhysicsCADAdministrationAgent

Get RunMat updates

New releases, guides and examples.

Product+
  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download
Math+
  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting
Physics+
  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA
Industries+
  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance
Learn+
  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students
Compare+
  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons
Company+
  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms

Product

  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download

Math

  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting

Physics

  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA

Industries

  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance

Learn

  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students

Compare

  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons

Company

  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms
GitHubXLinkedIn

© Dystr, Inc. · RunMat v0.7.1, Nov 17, 2026

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.

/
See all docs
Builtin Reference
    • colon
    • createArray
    • empty
    • eye
    • false
    • full
    • inf
    • int16.empty
    • int32.empty
    • int64.empty
    • int8.empty
    • linspace
    • logspace
    • magic
    • meshgrid
    • nan
    • ndgrid
    • nonzeros
    • ones
    • peaks
    • rand
    • randi
    • randn
    • randperm
    • range
    • sparse
    • spdiags
    • speye
    • spones
    • sprand
    • true
    • uint16.empty
    • uint32.empty
    • uint64.empty
    • uint8.empty
    • zeros

randn — Generate standard normal random numbers in MATLAB and RunMat.

randn draws pseudorandom samples from the standard normal distribution (μ = 0, σ = 1). Size forms and 'like' behavior follow MATLAB semantics.

Syntax

A = randn()
A = randn(n)
A = randn(size_vector)
A = randn(m, n, ...)
A = randn(..., typename)
A = randn(..., "like", prototype)

Inputs

n
Type
SizeArg
Required
Yes
Description
Square size.
size_vector
Type
SizeArg
Required
Yes
Description
Size vector defining output dimensions.
dims
Type
SizeArg
Required
Variadic
Description
Dimension sizes.
typename
Type
StringScalar
Required
No
Default
"double"
Description
Class override ('double'|'single'|'gpuArray').
like_kw
Type
StringScalar
Required
Yes
Default
"like"
Description
Like keyword.
prototype
Type
LikePrototype
Required
Yes
Description
Prototype array used for class/device.
NameTypeRequiredDefaultDescription
nSizeArgYes—Square size.
size_vectorSizeArgYes—Size vector defining output dimensions.
dimsSizeArgVariadic—Dimension sizes.
typenameStringScalarNo"double"Class override ('double'|'single'|'gpuArray').
like_kwStringScalarYes"like"Like keyword.
prototypeLikePrototypeYes—Prototype array used for class/device.

Returns

A
Type
NumericArray
Description
Normal random array (mean 0, variance 1).
NameTypeDescription
ANumericArrayNormal random array (mean 0, variance 1).

Errors

—
When
The 'like' keyword is provided without a prototype argument.
Message
randn: expected prototype after 'like'
—
When
A trailing option string is not supported.
Message
randn: unrecognised option
—
When
A prototype type cannot be used for randn(..., 'like', prototype).
Message
randn: unsupported prototype
—
When
Dimension arguments fail numeric/shape parsing.
Message
randn: dimension arguments must be numeric and nonnegative
IdentifierWhenMessage
—The 'like' keyword is provided without a prototype argument.randn: expected prototype after 'like'
—A trailing option string is not supported.randn: unrecognised option
—A prototype type cannot be used for randn(..., 'like', prototype).randn: unsupported prototype
—Dimension arguments fail numeric/shape parsing.randn: dimension arguments must be numeric and nonnegative

Behavior

randn() returns a scalar double drawn from 𝒩(0, 1).

randn(n) returns an n × n dense double matrix.

randn(m, n, ...) accepts an arbitrary number of dimension arguments.

randn(sz) accepts a documented row size vector; a column size vector is an independently gated RunMat-mode extension.

All eight integer classes are documented for scalar, separate-dimension, and row-size-vector controls and are decoded structurally from authoritative storage; resident size controls are separately gated RunMat extensions.

randn(___, 'like', A) matches the type, complexity, and residency of A, while ordinary size arguments determine shape and omission of size arguments returns a scalar. The old implicit randn(A) prototype form is not supported.

Complex prototypes yield complex Gaussian samples with independent real and imaginary parts, each having variance 1/2, so the complex sample has unit total variance.

Class specifiers support native 'single' and 'double'; integer and logical output prototypes are rejected before generation.

Execution and residency

Ordinary randn construction does not guarantee GPU residency. RunMat may select an accelerated route for a larger admitted computation. A resident 'like' prototype requests its owning provider and output class; an explicit gpuArray conversion is available when device residency is required.

CPU output consumes the session CPU stream controlled by rng. Explicit GPU or resident-like output consumes the independent GPU child stream controlled by gpurng; a selected provider may generate on device, or an admitted host-mediated route may compute from that same GPU stream and restore the exact GPU owner. Backend transcendental last bits are not promised identical.

Examples

Drawing a single standard normal variate

rng(0);
z = randn()

Creating a matrix of Gaussian noise

rng(0);
E = randn(2, 3)

Specifying dimensions with a size vector

rng(0);
shape = [2 2 2];
T = randn(shape)

Matching a gpuArray prototype and inspecting sample mean and standard deviation

gpurng(0);
G = gpuArray.zeros(512, 512);
noise = randn(512, 512, 'like', G);
stats = [mean(gather(noise(:))) std(gather(noise(:)))]

Generating complex Gaussian samples

rng(0);
z = randn(3, 1, 'like', 1 + 1i)

Producing reproducible noise for Monte Carlo tests

rng(0);
samples = randn(1, 5)

Using randn with coding agents

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

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

FAQ

What distribution does randn use?⌄

randn returns samples from the standard normal distribution with mean 0 and standard deviation 1.

How is randn different from rand?⌄

randn draws from a Gaussian distribution, whereas rand draws from the uniform distribution in [0, 1).

How do I control reproducibility?⌄

Use rng for ordinary CPU output and gpurng for explicit GPU or resident GPU-like output; the two streams are independent.

Does randn(___, 'like', A) work with complex prototypes?⌄

Yes. When A is complex, its real and imaginary components are independent normal variates with variance 1/2 each.

What happens if I request 'single' precision?⌄

RunMat returns a native single-precision tensor. A resident Single request uses a matching selected provider or a preselected host-mediated GPU-child route; a provider failure after effects never triggers a redraw.

How does randn behave on the GPU?⌄

GPU output uses the independent gpurng child stream. A selected provider may generate on device; an admitted host-mediated route uses the same child counters and restores GPU residency through the exact owner.

Can I request zero-sized dimensions?⌄

Yes. Any dimension argument equal to zero yields an empty array, matching MATLAB semantics.

Does randn fuse with other operations?⌄

No. Random generation is treated as a sink operation and excluded from fusion planning to preserve statistical properties.

Related Array functions

Creation

colon · createArray · empty · eye · false · full · inf · int16.empty · int32.empty · int64.empty · int8.empty · linspace · logspace · magic · meshgrid · nan · ndgrid · nonzeros · ones · peaks · rand · randi · randperm · range · sparse · spdiags · speye · spones · sprand · true · uint16.empty · uint32.empty · uint64.empty · uint8.empty · zeros

Accumulation

accumarray

Sorting Sets

argsort · intersect · ismember · ismembertol · issorted · issortedrows · setdiff · setxor · sort · sortrows · union · unique

Shape

blkdiag · cat · circshift · diag · flip · fliplr · flipud · horzcat · ipermute · kron · permute · repelem · repmat · reshape · rot90 · shiftdim · squeeze · toeplitz · tril · triu · vertcat

Combinatorics

combinations · nchoosek · perms

Binning

discretize

Indexing

find · ind2sub · sub2ind

Grouping

findgroups · groupcounts · grp2idx · splitapply

Introspection

height · iscolumn · isempty · ismatrix · isrow · isscalar · isvector · length · ndims · numel · size · width

Source you can read

Every RunMat function's source is public. Read exactly how randn is executed, line by line, in Rust.

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

About RunMat

RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/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
  • Behavior
  • Execution and residency
  • Examples
  • Drawing a single standard normal variate
  • Creating a matrix of Gaussian noise
  • Specifying dimensions with a size vector
  • Matching a gpuArray prototype and inspecting sample mean and standard deviation
  • Generating complex Gaussian samples
  • Producing reproducible noise for Monte Carlo tests
  • Using randn with coding agents
  • FAQ
  • Related Array functions
  • Creation
  • Accumulation
  • Sorting Sets
  • Shape
  • Combinatorics
  • Binning
  • Indexing
  • Grouping
  • Introspection
  • Source you can read
  • About RunMat