RandomChoice[{e1,e2,…}]
gives a pseudorandom choice of one of the ei.
RandomChoice[list,n]
gives a list of n pseudorandom choices.
RandomChoice[list,{n1,n2,…}]
gives an n1×n2×… array of pseudorandom choices.
RandomChoice[{w1,w2,…}{e1,e2,…}]
gives a pseudorandom choice weighted by the wi.
RandomChoice[wlistelist,n]
gives a list of n weighted choices.
RandomChoice[wlistelist,{n1,n2,…}]
gives an n1×n2×… array of weighted choices.
RandomChoice
RandomChoice[{e1,e2,…}]
gives a pseudorandom choice of one of the ei.
RandomChoice[list,n]
gives a list of n pseudorandom choices.
RandomChoice[list,{n1,n2,…}]
gives an n1×n2×… array of pseudorandom choices.
RandomChoice[{w1,w2,…}{e1,e2,…}]
gives a pseudorandom choice weighted by the wi.
RandomChoice[wlistelist,n]
gives a list of n weighted choices.
RandomChoice[wlistelist,{n1,n2,…}]
gives an n1×n2×… array of weighted choices.
Details
- RandomChoice is also known as simple random sampling or sampling with replacement.
- RandomChoice[{e1,e2,…}] chooses with equal probability between all of the ei.
- RandomChoice[i;;j;;k,n] may be used to sample the Span from i to j in steps of k.
- RandomChoice gives a different sequence of pseudorandom choices whenever you run the Wolfram Language. You can start with a particular seed using SeedRandom.
- A Method option to SeedRandom can be given to specify the pseudorandom generator used.
Examples
open all close allBasic Examples (4)
Choose among
,
, and
at random:
RandomChoice[{a, b, c}]RandomChoice[{a, b, c}, 20]A 4×3 array of random choices:
RandomChoice[{a, b, c}, {4, 3}]Choices weighted with probabilities:
RandomChoice[{0.2, 0.2, 0.6} -> {a, b, c}, 20]Weights are automatically normalized:
RandomChoice[{2, 2, 6} -> {a, b, c}, 20]Scope (2)
The choices can be any expressions:
RandomChoice[{Exp[x], x ^ 2, 1 / x, 2}, 10]RandomChoice[{a -> 1, a -> 4, b -> 6}, 10]Choose among all numbers between -10 and 10:
RandomChoice[-10 ;; 10, 10]Choose among even numbers between -10 and 10:
RandomChoice[-10 ;; 10 ;; 2, 10]Applications (9)
RandomChoice[{"A", "C", "G", "T"}, 50]StringJoin[%]Generate a weighted random string:
StringJoin[RandomChoice[{4, 1} -> {"A", "B"}, 80]]Generate integers according to a
distribution:
RandomChoice[Table[1 / n, {n, 10}] -> Range[10], 30]Random array of color choices:
ArrayPlot[RandomChoice[{Red, Green, Blue}, {20, 20}]]A random walk with steps of unit length:
ListLinePlot[Accumulate[RandomChoice[{-1, 1}, 50]]]Graphics[Line[Accumulate[RandomChoice[{-1, 1}, {1000, 2}]]]]Random walk on a hexagonal lattice:
Graphics[Line[Accumulate[RandomChoice[Table[{Sin[2Pi i / 6], Cos[2Pi i / 6]}, {i, 6}], 1000]]]]Randomly generate disks or circles:
Graphics[Table[RandomChoice[{Disk, Circle}][2{i, j}], {i, 5}, {j, 5}]]A random graph with 1% of possible edges filled in:
GraphPlot[RandomChoice[{0.01, 0.99} -> {1, 0}, {100, 100}]]Properties & Relations (2)
Use SeedRandom to get repeatable random values:
{RandomChoice[{a, b, c}, 5], RandomChoice[{a, b, c}, 5]}{SeedRandom[1234];RandomChoice[{a, b, c}, 5], SeedRandom[1234];RandomChoice[{a, b, c}, 5]}Use BlockRandom to block one use of RandomChoice from affecting others:
{BlockRandom[RandomChoice[Range[100]]], RandomChoice[Range[100]]}Neat Examples (5)
Pick 10 random words beginning with "a" from the dictionary:
RandomChoice[DictionaryLookup["a" ~~ ___], 10]Pick 10 random Wolfram Language functions:
RandomChoice[Names["*"], 10]Make a continuous string of characters:
StringJoin[RandomChoice[CharacterRange["a", "z"], 80]]Break the characters into "words":
StringJoin[RandomChoice[{1, 5} -> {" ", #}]& /@ RandomChoice[CharacterRange["a", "z"], 80]]2D random walk with eight directions:
Graphics[Line[Accumulate[RandomChoice[{-1, 0, 1}, {1000, 2}]]]]Graphics3D[Line[Accumulate[RandomChoice[{-1, 1}, {1000, 3}]]]]See Also
RandomInteger RandomSample RandomVariate SeedRandom BlockRandom Span RandomEntity CategoricalDistribution
Function Repository: RandomPartChoice SampleRebalance
Tech Notes
Related Guides
Text
Wolfram Research (2007), RandomChoice, Wolfram Language function, https://reference.wolfram.com/language/ref/RandomChoice.html (updated 2014).
CMS
Wolfram Language. 2007. "RandomChoice." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2014. https://reference.wolfram.com/language/ref/RandomChoice.html.
APA
Wolfram Language. (2007). RandomChoice. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RandomChoice.html
BibTeX
@misc{reference.wolfram_2026_randomchoice, author="Wolfram Research", title="{RandomChoice}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/RandomChoice.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_randomchoice, organization={Wolfram Research}, title={RandomChoice}, year={2014}, url={https://reference.wolfram.com/language/ref/RandomChoice.html}, note=[Accessed: 13-June-2026]}