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

RandomInteger

RandomInteger
gives a pseudorandom integer in the range .
RandomInteger
gives a pseudorandom integer in the range .
RandomInteger
pseudorandomly gives 0 or 1.
RandomInteger
gives a list of n pseudorandom integers.
RandomInteger
gives an ××... array of pseudorandom integers.
  • RandomInteger chooses integers in the range 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 3×4 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 3×4 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