Skip to Main Content Skip to Search
Product Documentation

randint - Generate matrix of uniformly distributed random integers

Syntax

out = randint
out = randint(m)
out = randint(m,n)
out = randint(m,n,rg)
out = randint(m,n,rg,state)

Description

out = randint generates a random scalar that is either 0 or 1, with equal probability.

out = randint(m) generates an m-by-m binary matrix, each of whose entries independently takes the value 0 with probability 1/2.

out = randint(m,n) generates an m-by-n binary matrix, each of whose entries independently takes the value 0 with probability 1/2.

out = randint(m,n,rg) generates an m-by-n integer matrix. If rg is zero, out is a zero matrix. Otherwise, the entries are uniformly distributed and independently chosen from the range

out = randint(m,n,rg,state) is the same as the syntax above, except that it first resets the state of the uniform random number generator rand to the integer state.

This function uses, by default, the Mersenne Twister algorithm by Nishimura and Matsumoto.

Examples

To generate a 10-by-10 matrix whose elements are uniformly distributed in the range from 0 to 7, use either of the following commands.

out = randint(10,10,[0,7]);
out = randint(10,10,8);

See Also

rand | randerr | randsrc

How To

  


Free Early Verification Kit

Learn how to apply early verification to your development process through these technical resources.

How much time do you spend on testing to ensure implementation meets system-level requirements?

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS