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 >

RandomInteger

RandomInteger[{imin, imax}]
gives a pseudorandom integer in the range {i_(min),...,i_(max)}.
RandomInteger[imax]
gives a pseudorandom integer in the range {0,...,i_(max)}.
RandomInteger[]
pseudorandomly gives 0 or 1.
RandomInteger[range, n]
gives a list of n pseudorandom integers.
RandomInteger[range, {n1, n2, ...}]
gives an n_1xn_2x... array of pseudorandom integers.
RandomInteger[dist, ...]
samples from the symbolic discrete distribution dist.
  • RandomInteger[{imin, imax}] chooses integers in the range {i_(min),...,i_(max)} with equal probability.
  • RandomInteger gives a different sequence of pseudorandom integers 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.
A random integer in the range 1 through 10:
A random integer in the range 0 through 3:
A random choice of 0 or 1:
20 random integers in the range 0 through 5:
A 3x4 random array of 0s and 1s:
A random integer in the range 1 through 10:
In[1]:=
Click for copyable input
Out[1]=
 
A random integer in the range 0 through 3:
In[1]:=
Click for copyable input
Out[1]=
 
A random choice of 0 or 1:
In[1]:=
Click for copyable input
Out[1]=
 
20 random integers in the range 0 through 5:
In[1]:=
Click for copyable input
Out[1]=
 
A 3x4 random array of 0s and 1s:
In[1]:=
Click for copyable input
Out[1]=
Generate random integers of any size:
A cellular automaton with random initial conditions:
Random circles at integer positions:
Random array of black and white cells:
Count how many pairs of random integers between 1 and a million are relatively prime:
Use SeedRandom to get repeatable random values:
Use BlockRandom to block one use of RandomInteger from affecting others:
RandomInteger generates a uniform distribution, here with mean 5:
A randomly filled cubic lattice:
New in 6
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team