Random Integers

The randint function generates random integer matrices whose entries are in a range that you specify. A special case generates random binary matrices.

For example, the command below generates a 5-by-4 matrix containing random integers between 2 and 10.

c = randint(5,4,[2,10])

c =

     2     4     4     6
     4     5    10     5
     9     7    10     8
     5     5     2     3
    10     3     4    10

If your desired range is [0,10] instead of [2,10] then you can use either of the commands below. They produce different numerical results, but use the same distribution.

d = randint(5,4,[0,10]);
e = randint(5,4,11);


© 1994-2005 The MathWorks, Inc.