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[{e1,e2,}] chooses with equal probability between all of the ei.
  • 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 allclose all

Basic Examples  (4)

Choose among , , and at random:

In[1]:=
Click for copyable input
Out[1]=

A list of 20 random choices:

In[1]:=
Click for copyable input
Out[1]=

A 4×3 array of random choices:

In[1]:=
Click for copyable input
Out[1]=

Choices weighted with probabilities:

In[1]:=
Click for copyable input
Out[1]=

Weights are automatically normalized:

In[2]:=
Click for copyable input
Out[2]=

Scope  (2)

Applications  (9)

Properties & Relations  (2)

Neat Examples  (5)

See Also

RandomInteger  RandomSample  RandomReal  SeedRandom  BlockRandom  Part  RandomEntity

Tutorials

Introduced in 2007
(6.0)