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

binornd — Generate binomially distributed random samples.

binornd draws from binomial distributions with scalar parameter expansion, explicit shape forms, deterministic RunMat random-state integration, and validated provider residency.

Syntax

r = binornd(n, p)
r = binornd(n, p, sz)
r = binornd(n, p, sz1, sz2, ...)

Inputs

n
Type
NumericArray
Required
Yes
Description
Positive integer trial counts supplied as dense real single or double values.
p
Type
NumericArray
Required
Yes
Description
Success probabilities in the inclusive interval from zero to one.
sz
Type
SizeArg
Required
Yes
Description
Output size as one scalar or one row vector.
sz1, sz2, ...
Type
SizeArg
Required
Variadic
Description
Output dimension sizes supplied as separate scalar values.
NameTypeRequiredDefaultDescription
nNumericArrayYes—Positive integer trial counts supplied as dense real single or double values.
pNumericArrayYes—Success probabilities in the inclusive interval from zero to one.
szSizeArgYes—Output size as one scalar or one row vector.
sz1, sz2, ...SizeArgVariadic—Output dimension sizes supplied as separate scalar values.

Returns

r
Type
NumericArray
Description
Binomially distributed samples with the requested shape.
NameTypeDescription
rNumericArrayBinomially distributed samples with the requested shape.

Errors

RunMat:binornd:InvalidArgument
When
Parameters or size controls are missing, unsupported, outside their domains, or shape-incompatible.
Message
binornd: invalid argument
RunMat:binornd:Internal
When
Random-state access, allocation, provider gather, or output restoration fails.
Message
binornd: internal error
RunMat:binornd:TooManyOutputs
When
More than one output is requested.
Message
binornd: too many output arguments
IdentifierWhenMessage
RunMat:binornd:InvalidArgumentParameters or size controls are missing, unsupported, outside their domains, or shape-incompatible.binornd: invalid argument
RunMat:binornd:InternalRandom-state access, allocation, provider gather, or output restoration fails.binornd: internal error
RunMat:binornd:TooManyOutputsMore than one output is requested.binornd: too many output arguments

Parameters and output shape

binornd(n,p) draws independent binomial samples. Each value of n must be a positive integer trial count, and each probability in p must be between zero and one, inclusive. A scalar parameter expands to the shape of the other parameter; two nonscalar parameters must have matching shapes.

Without size controls, the output follows the scalar-expanded parameter shape. A single scalar size creates a square matrix. A row-vector size or separate scalar dimensions selects an explicit shape, which must match every nonscalar parameter. Nonpositive dimensions produce an empty array, and trailing singleton dimensions beyond the second are ignored.

Classes and RunMat extensions

The documented parameter and size classes are dense real single and double. If either distribution parameter is single, the result is single; otherwise it is double. Size controls select shape only.

RunMat compatibility mode also accepts all eight fixed-width integer classes for either parameter and for size controls, plus logical values for n or p. Integer parameters must be exactly representable at the binary64 sampling boundary. Integer size values are decoded directly from authoritative storage.

Random state, provider arrays, and distributed arrays

binornd uses RunMat's shared deterministic random state. Calling rng("default") resets the sequence used by later calls.

Floating provider parameters preserve output class and residency when their exact owner can represent the result. Sampling currently uses the host RNG and restores the result through that owner. Explicit provider residency must be preserved or the call fails.

Distributed parameter arrays are materialized before sampling, so the returned array is host-resident. Values and documented scalar-expansion behavior are preserved across that boundary.

Examples

Generate a matrix of binomial samples

rng("default");
r = binornd(10, 0.5, 2, 3)

Expected output:

r is a 2-by-3 double matrix with values from 0 through 10

Use several trial counts and probabilities

rng("default");
n = [2 4 6 8];
p = [0.2 0.4 0.6 0.8];
r = binornd(n, p)

Expected output:

r follows the 1-by-4 parameter shape

Generate native single-precision samples

rng("default");
r = binornd(10, single([0.2 0.5 0.8]))

Expected output:

r is a 1-by-3 single array

Use deterministic probability endpoints

rng("default");
r = binornd([3 5], [0 1])

Expected output:

r is [0 5]

Use fixed-width parameters and sizes

rng("default");
r = binornd(uint16(8), uint8(1), uint16([2 2]))

Expected output:

r is a 2-by-2 double matrix containing 8

Preserve explicit provider residency

rng("default");
p = gpuArray(single([0.2 0.5 0.8]));
gr = binornd(10, p);
r = gather(gr)

Expected output:

gr remains a single-precision gpuArray

Using binornd with coding agents

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

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

FAQ

Can n be fractional?⌄

No. Every trial count must be a positive integer.

How are array parameters combined?⌄

A scalar expands to the other parameter's shape. Two nonscalar parameters must have the same shape; binornd does not apply general singleton-dimension expansion.

Which class does binornd return?⌄

A single n or p selects single output. Otherwise the result is double. Size controls never select the class.

Can a call be reproduced?⌄

Yes. Call rng("default") before the operation to reset RunMat's shared deterministic random state.

Does binornd accept fixed-width integers?⌄

RunMat mode accepts exact fixed-width parameters and structural sizes. MATLAB compatibility mode restricts the call to documented single and double inputs.

What happens to a gpuArray input?⌄

RunMat samples through its shared host RNG and restores class and residency through the exact input owner. Explicit residency cannot be silently discarded.

Related Stats functions

Random

bootstrp · datasample · dividerand · exprnd · gamrnd · gpurng · 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 binornd is executed, line by line, in Rust.

  • View the source for binornd 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
  • Parameters and output shape
  • Classes and RunMat extensions
  • Random state, provider arrays, and distributed arrays
  • Examples
  • Generate a matrix of binomial samples
  • Use several trial counts and probabilities
  • Generate native single-precision samples
  • Use deterministic probability endpoints
  • Use fixed-width parameters and sizes
  • Preserve explicit provider residency
  • Using binornd with coding agents
  • FAQ
  • Related Stats functions
  • Random
  • Summary
  • Ml
  • Hist
  • Options
  • Source you can read
  • About RunMat