Although Jonas' solution is really nice, randi
isn't in some of the early versions of MATLAB. I believe all versions have rand
. A solution using rand
would be:
randomIntergers = floor(a + (b-a+1) .* rand(20,1));
where [a,b] is the range of values you want a distribution over.
If you are use round(a + (b-a))
you will have a nonuniform effect on the values of 'a' and 'b'. This can be confirmed using the hist()
function. This is because the domain that maps into 'a' and 'b' is half the size for all other members of the range.