Random Integers
This example shows how to create an array of random integer values that are drawn from a discrete uniform distribution on the set of numbers –10, –9,...,9, 10.
The simplest randi
syntax returns double-precision integer values between 1 and a specified value, imax
. To specify a different range, use the imin
and imax
arguments together.
First, initialize the random number generator to make the results in this example repeatable.
rng(0,'twister');
Create a 1-by-1000 array of random integer values drawn from a discrete uniform distribution on the set of numbers -10, -9,...,9, 10. Use the syntax, randi([imin imax],m,n)
.
r = randi([-10 10],1,1000);
Verify that the values in r
are within the specified range.
[rmin,rmax] = bounds(r)
rmin = -10
rmax = 10