Depends whether they have to be integers or can be 'real' (floating point) numbers. Also, do you want the values 1 and 80 to be included?
In any case, there is this matlab help very useful.
As usually when working with random numbers you need to initialize the random generator.
rng(0,'twister');
This is used for you to be able to reproduce your results, so beware if you always use the same seed (0 in this case) you will always get the same results.
the typical trick to randomize that is to use the current time as seed,
rng(posixtime(datetime('now')),'twister');
Given that you said you wanted an array of 5 numbers,
N = 5;
rand(N,M)
returns a matrix of NxM
uniformly distributed numbers in the interval (0,1)
, then you need the following transformation to bring them to your interval (a,b)
((1,80)
in your case)
a = 1;
b = 80;
r = (b-a).*rand(N,1) + a;
output:
>> a = 1;
b = 80;
r = (b-a).*rand(N,1) + a
r =
65.5670
69.6269
7.6704
32.5828
21.5298
If you were looking for integers in the interval [1,80]
(note that now the interval includes the values 1 and 80), then this would do it,
r = randi(80,N,1);
output:
>> r = randi(80,N,1)
r =
65
35
73
15
22