This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

RandomChoice

RandomChoice
gives a pseudorandom choice of one of the .
RandomChoice
gives a list of n pseudorandom choices.
RandomChoice
gives an ××... array of pseudorandom choices.
RandomChoice
gives a pseudorandom choice weighted by the .
RandomChoice
gives a list of n weighted choices.
RandomChoice
gives an ××... array of weighted choices.
  • RandomChoice chooses with equal probability between all of the .
  • 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 , , and at random:
A list of 20 random choices:
A 4×3 array of random choices:
Choices weighted with probabilities:
Weights are automatically normalized:
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]=
The choices can be any expressions:
Generate a random string:
Generate a weighted random string:
Generate integers according to a 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