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
    • binornd
    • bootstrp
    • datasample
    • dividerand
    • exprnd
    • gamrnd
    • gpurng
    • lhsdesign
    • mvnrnd
    • normrnd
    • random
    • randsample
    • rng
    • trnd
    • unidrnd
    • unifrnd
    • wblrnd

gpurng — Control the independent GPU random stream.

gpurng queries, seeds, and restores RunMat's session GPU random stream independently of the CPU rng stream.

Syntax

s = gpurng()
s = gpurng(seed|generator|option|state)
s = gpurng(seed,generator)

Inputs

seed, generator, option, or state
Type
Any
Required
Yes
Default
—
Description
Nonnegative seed, generator, default/shuffle option, or prior snapshot.
seed
Type
NumericScalar
Required
Yes
Default
—
Description
Nonnegative integer seed below 2^32.
generator
Type
StringScalar
Required
Yes
Default
—
Description
GPU random generator algorithm.
NameTypeRequiredDefaultDescription
seed, generator, option, or stateAnyYes—Nonnegative seed, generator, default/shuffle option, or prior snapshot.
seedNumericScalarYes—Nonnegative integer seed below 2^32.
generatorStringScalarYes—GPU random generator algorithm.

Returns

s
Type
Any
Description
Previous GPU stream snapshot with Type, Seed, and State fields.
NameTypeDescription
sAnyPrevious GPU stream snapshot with Type, Seed, and State fields.

Errors

RunMat:gpurng:InvalidArgument
When
A seed or opaque snapshot is malformed.
Message
gpurng: invalid argument
RunMat:gpurng:GeneratorUnsupported
When
A documented generator has no implemented request-bound route.
Message
gpurng: generator is not supported by this runtime
IdentifierWhenMessage
RunMat:gpurng:InvalidArgumentA seed or opaque snapshot is malformed.gpurng: invalid argument
RunMat:gpurng:GeneratorUnsupportedA documented generator has no implemented request-bound route.gpurng: generator is not supported by this runtime

Independent GPU random state

gpurng queries or changes the session GPU random stream used by GPU output forms of rand, randi, randn, and randperm. rng controls the separate ordinary CPU stream; seeding one does not reseed the other. Automatic placement of an ordinary CPU random call must not change its stream or draw order.

gpurng("default") selects Threefry4x64_20 with seed zero. A numeric seed restarts the current GPU generator; gpurng("shuffle") chooses a fresh seed. The returned scalar structure records the previous Type, Seed, and opaque State, and a prior returned snapshot can be restored.

Generator availability and execution

The documented GPU algorithms are Threefry, Philox, and CombRecursive. This RunMat implementation currently executes Threefry; requests for the other algorithms fail before changing the stream. They are not aliases of Threefry. Snapshot bytes are RunMat-owned state, not a claim of byte-for-byte compatibility with MATLAB's opaque state encoding.

A request-bound GPU child range determines each output independently of execution placement. Supported provider forms can generate on the device; other admitted forms may compute from the GPU child stream on the host and restore the requested GPU residency through the exact owner. An operational provider failure after effects is terminal, not a signal to draw again on another route.

Threefry words and normal Box-Muller inputs follow the same RunMat child mapping across supported providers. Floating transcendental last bits may differ by backend. The default seed and generator identity do not assert MATLAB's undocumented seed-to-counter or distribution-lane mapping.

Examples

Save and restore GPU random state

gpurng('default'); s = gpurng; a = rand(2,2,'gpuArray'); gpurng(s); b = rand(2,2,'gpuArray'); same = isequal(gather(a),gather(b))

Expected output:

same is true after the GPU state is restored

Seed CPU and GPU streams separately

rng('default'); gpurng('default'); cpu = rand(1,3); gpu = gather(rand(1,3,'gpuArray'))

Expected output:

cpu and gpu are each reproducible from their own defaults

Using gpurng with coding agents

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

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

FAQ

Does rng seed the GPU stream?⌄

No. Use gpurng for GPU random output. rng and gpurng control independent session streams.

Can I restore a GPU stream?⌄

Yes. Capture s = gpurng, then call gpurng(s) to restore that RunMat snapshot.

Are Philox and CombRecursive supported?⌄

They are documented GPU generators, but remain unimplemented in RunMat and are rejected before stream mutation; they are not renamed Threefry streams.

Related Stats functions

Random

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

Summary

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

Ml

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

Hist

histc · histcounts · histcounts2

Options

statget · statset

Source you can read

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

  • View the source for gpurng 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
  • Independent GPU random state
  • Generator availability and execution
  • Examples
  • Save and restore GPU random state
  • Seed CPU and GPU streams separately
  • Using gpurng with coding agents
  • FAQ
  • Related Stats functions
  • Random
  • Summary
  • Ml
  • Hist
  • Options
  • Source you can read
  • About RunMat