Skip to content

RandomVariate ​

A random draw from a distribution, or a list of them -- Random over the distribution, by its Wolfram name.

RandomVariate(dist)one draw.
RandomVariate(dist, n)a list of nn draws.
Typed signatures
TypePackageApplies
(any, integer<0..>?) random -> anystatisticsalways

Domain: Statistics

Details
  • Seeded, not free-running — same convention as SeedRandom/RandomInteger in @enumeratio/combinatorics/collections: call SeedRandom(seed) first for a reproducible sequence; without it, a fixed default seed makes even a bare call reproducible run to run. This file's draws are their OWN stream, independent of RandomInteger's, even after the same SeedRandom call — a follow-up once collections' own seeded RandomInteger lands is to unify both under one engine-level generator.
  • The generator is our own (mulberry32, the same algorithm RandomInteger uses), not Wolfram's — the same seed draws a different sequence. Only the shape and (for NormalDistribution/UniformDistribution/…) approximate range of the answer are guaranteed to match.
  • Sampling method by distribution — NormalDistribution/BinormalDistribution: Box–Muller; UniformDistribution: inverse CDF; PoissonDistribution: Knuth's algorithm; BinomialDistribution: a sum of Bernoulli draws; GammaDistribution/BetaDistribution: Marsaglia–Tsang; EmpiricalDistribution: uniform resampling with replacement.

Examples

Basic #

With no SeedRandom call, a fixed default seed still makes this reproducible

live ↗
InRandomVariate(NormalDistribution⁡(0,1))\mathrm{RandomVariate}(\operatorname{NormalDistribution}(0, 1))Out−0.956 162 229 384 149-0.956\,162\,229\,384\,149
Scope #
live ↗
InLast([SeedRandom(1),RandomVariate(UniformDistribution⁡([0,1]),3)])\mathrm{Last}(\bigl\lbrack\mathrm{SeedRandom}(1), \mathrm{RandomVariate}(\operatorname{UniformDistribution}(\bigl\lbrack0, 1\bigr\rbrack), 3)\bigr\rbrack)Out[0.627 073 940 588 161 3,0.002 735 721 180 215 478,0.527 447 039 959 952 2]\bigl\lbrack0.627\,073\,940\,588\,161\,3, 0.002\,735\,721\,180\,215\,478, 0.527\,447\,039\,959\,952\,2\bigr\rbrack
live ↗
InLast([SeedRandom(1),RandomVariate(PoissonDistribution⁡(4))])\mathrm{Last}(\bigl\lbrack\mathrm{SeedRandom}(1), \mathrm{RandomVariate}(\operatorname{PoissonDistribution}(4))\bigr\rbrack)Out11
live ↗
InLast([SeedRandom(2),RandomVariate(EmpiricalDistribution([a,b,c]))])\mathrm{Last}(\bigl\lbrack\mathrm{SeedRandom}(2), \mathrm{RandomVariate}(\mathrm{EmpiricalDistribution}(\bigl\lbrack a, b, c\bigr\rbrack))\bigr\rbrack)Outcc
Properties & Relations #

RandomVariate is Random over the distribution: the same draw from the same stream

live ↗
InLast([SeedRandom(5),RandomVariate(NormalDistribution⁡(0,1))])=Last([SeedRandom(5),Random(NormalDistribution⁡(0,1))])\mathrm{Last}(\bigl\lbrack\mathrm{SeedRandom}(5), \mathrm{RandomVariate}(\operatorname{NormalDistribution}(0, 1))\bigr\rbrack)=\mathrm{Last}(\bigl\lbrack\mathrm{SeedRandom}(5), \mathrm{Random}(\operatorname{NormalDistribution}(0, 1))\bigr\rbrack)OutTrue\mathrm{True}
About
Examples5

See also: SeedRandom, Distributed