Step-by-step explanation:
The Matlab function rand() is used to generate uniformly distributed random numbers of a given size over the interval (0, 1)
Syntax:
num = rand(N, 1)
Where num is a variable to store the random numbers
N is the number of random numbers you want to generate.
Example:
For the given problem we have to generate one random number for each person in the class of 50 people.
num = rand(50,1)
It returns 50 random numbers in the range 0 to 1 which are given in the output section.
You can also modify the range of interval by adding the following code
num = x + (y - x).*rand(1,50)
Where x is the lower limit of the range and y is the upper limit of the range.
for example
num = 50 + (100 - 50).*rand(1,50)
it will generate random numbers in the range of 50 to 100. Here .* is used for the bit-wise multiplication
Note:
Do not write rand(50) it will return a 50 by 50 matrix of random numbers.
Output:
num =
0.582139
0.540686
0.350985
0.115957
0.652881
0.195352
0.425562
0.367363
0.169750
0.800792
0.267118
0.586340
0.698618
0.975052
0.235557
0.757331
0.117483
0.295195
0.624606
0.857645
0.196915
0.645716
0.041070
0.718010
0.469060
0.116754
0.256292
0.472404
0.221682
0.888215
0.379500
0.464798
0.604826
0.521442
0.351424
0.730017
0.459121
0.241424
0.140979
0.729892
0.600992
0.961623
0.781636
0.671102
0.628573
0.660506
0.605492
0.033747
0.659619
0.274432