MATLAB: How to specify , n ,the number of random integers

random number generator

Write a Matlab function r = random(x,y) which takes as input two integers x and y, and generates and returns a random integer that is equally likely to take any value between x and y?
Then, write a program use random() to generate 100,000 random numbers between 1 and 10. Store each random number in an vector.
Heres what I got so far:
function r = random(x,y) r = floor(x + y.*rand(n,1)) ??? end
program: n = 100000; x = 1; y = 10; r = random(x,y);

Best Answer

1
function r = random(x,y)
r = round(x + (y-x).*rand); end
OR
random = @(x,y)randi([x, y])
2
function r = randomn(x,y,n)
r = round(x + (y-x).*rand(n,1));
OR
randomn = @(x,y,n)randi([x y],n,1)
more
randomn = @(x,y,n)arrayfun(@(i1)random(x , y),(1:n)')