Skip to content

Random ​

A random element of a domain: uniform over a finite collection or an interval, or drawn from a distribution; with a count or shape, that many draws.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageRandomReal✓
Random()A real in [0,1)[0, 1).
Random(domain, shape)One draw from a finite collection, uniform by index, or an interval; with a count, that many draws, and with a list of dimensions, an array of that shape. Every draw comes from the engine's one seeded stream, restarted by SeedRandom.
Random(dist, shape)Draws from a distribution, by its own sampler.
Typed signatures
TypePackageApplies
(() random -> real) & ((collection<any> | set<real>) random -> any) & ((collection<any> | set<real>, integer<0..> | list<integer<0..>>) random -> list)combinatoricsreplaces compute-enginealways
(() random -> real) & ((collection<any> | set<real>) random -> any) & ((collection<any> | set<real>, integer<0..> | list<integer<0..>>) random -> list) & ((distribution, (integer<0..> | list<integer<0..>>)?) random -> any)statisticsreplaces combinatoricsalways
((collection<any> | set<real>)?) random -> anycompute-enginealways

Domain: Compute engine

Examples

Basic #

one permutation of {1,2,3,4}\{1, 2, 3, 4\}, drawn uniformly by index from the collection; seeded, so it is the same every time

live ↗
InLast([SeedRandom(4),Random(Permutations(4))])\mathrm{Last}(\bigl\lbrack\mathrm{SeedRandom}(4), \mathrm{Random}(\mathrm{Permutations}(4))\bigr\rbrack)OutPermutation⁡([4,3,1,2]){\operatorname{Permutation}}([4, 3, 1, 2])
Scope #

a count after the domain draws that many elements

live ↗
InLength(Last([SeedRandom(1),Random(IntegerPartitions(10),3)]))\mathrm{Length}(\mathrm{Last}(\bigl\lbrack\mathrm{SeedRandom}(1), \mathrm{Random}(\mathrm{IntegerPartitions}(10), 3)\bigr\rbrack))Out33
Properties & Relations #

RandomInteger is its Wolfram spelling over a Range: the same draw from the same stream

live ↗
InLast([SeedRandom(5),RandomInteger([10,20])])=Last([SeedRandom(5),Random(10..20)])\mathrm{Last}(\bigl\lbrack\mathrm{SeedRandom}(5), \mathrm{RandomInteger}(\bigl\lbrack10, 20\bigr\rbrack)\bigr\rbrack)=\mathrm{Last}(\bigl\lbrack\mathrm{SeedRandom}(5), \mathrm{Random}(10..20)\bigr\rbrack)OutTrue\mathrm{True}
About
Examples3
Checked againstWolfram Language 2 agreeCombinatorica 1 agree
CrosswalkWolfram Language

See also: SeedRandom, RandomInteger, RandomVariate