r1 = rand(1000,1);
r1is a 1000-by-1 column vector containing real floating-point numbers drawn from a uniform distribution. All the values in
r1are in the open interval (0, 1). A histogram of these values is roughly flat, which indicates a fairly uniform sampling of numbers.
randi function returns
values drawn from a discrete uniform distribution. For example,
r2 = randi(10,1000,1);
r2is a 1000-by-1 column vector containing integer values drawn from a discrete uniform distribution whose range is 1,2,...,10. A histogram of these values is roughly flat, which indicates a fairly uniform sampling of integers between 1 and 10.
randn function returns arrays of real
floating-point numbers that are drawn from a standard normal distribution.
r3 = randn(1000,1);
r3is a 1000-by-1 column vector containing numbers drawn from a standard normal distribution. A histogram of
r3looks like a roughly normal distribution whose mean is 0 and standard deviation is 1.
You can use the
randperm function to create
arrays of random integer values that have no repeated values. For
r4 = randperm(15,5);
r4is a 1-by-5 array containing randomly selected integer values on the closed interval, [1, 15]. Unlike
randi, which can return an array containing repeated values, the array returned by
randpermhas no repeated values.
Successive calls to any of these functions return different results. This behavior is useful for creating several different arrays of random values.