Illustrations of calling the rand function:
The function ‘rand’ can be used to produce random real numbers; calling it produces one random real number in the range from 0 to 1. There is no argument passed to the rand function. Here are two illustrations of calling the rand function:
>> rand
ans =
0.9501
>> rand
ans =
0.2311
The seed for the rand function will always be similar each time the MATLAB is started, unless the state is changed, for illustration shown:
rand(‘state’,sum(100*clock))
This uses the present date and time which are returned from the built-in clock function to set the seed. Note: this is completed only once in any given MATLAB session to set the seed; the rand function can be used as shown earlier in any number of times to produce random numbers.
As rand returns a real number in the range from 0 to 1, multiplying the answer by an integer N would return the random real number in a range from 0 to N. For illustration, multiplying by 10 returns a real in the range from 0 to 10, therefore this expression
rand*10
would return the outcome in the range from 0 to 10.