Mathematica 9 is now available
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
Mathematica > Data Manipulation > Statistics > Random Number Generation >
Mathematica > Mathematics and Algorithms > Mathematical Functions > Random Number Generation >
Mathematica > Mathematics and Algorithms > Statistics > Random Number Generation >

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 n1Crossn2Cross... array of pseudorandom choices.
RandomChoice[{w1, w2, ...}->{e1, e2, ...}]
gives a pseudorandom choice weighted by the wi.
RandomChoice[wlist->elist, n]
gives a list of n weighted choices.
RandomChoice[wlist->elist, {n1, n2, ...}]
gives an n_1xn_2x... array of weighted choices.
  • RandomChoice[{e1, e2, ...}] chooses with equal probability between all of the ei.
  • RandomChoice gives a different sequence of pseudorandom choices whenever you run Mathematica. You can start with a particular seed using SeedRandom.
  • A Method option to SeedRandom can be given to specify the pseudorandom generator used.
Choose among a, b and c at random:
A list of 20 random choices:
A 4x3 array of random choices:
Choices weighted with probabilities:
Weights are automatically normalized:
Choose among a, b and c 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 4x3 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]=
The choices can be any expressions:
Generate a random string:
Generate a weighted random string:
Generate integers according to a 1/n distribution:
Random array of color choices:
A random walk with steps of unit length:
2D random walk:
Random walk on a hexagonal lattice:
Randomly generate disks or circles:
A random graph with 1% of possible edges filled in:
Use SeedRandom to get repeatable random values:
Use BlockRandom to block one use of RandomChoice from affecting others:
Pick 10 random words beginning with "a" from the dictionary:
Pick 10 random Mathematica functions:
Make a continuous string of characters:
Break the characters into "words":
2D random walk with eight directions:
3D lattice random walk:
New in 6
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team