MATLAB: Random number gerator problem

histogramhomeworkMATLABrandom number generator

The question that i am working on is as follows
Write a function called randomness that takes three input arguments: limit, n, and m, in that order. The function returns an n-by-m matrix of uniformly distributed random integers between 1 and limit inclusive. You are not allowed to use randi, but you can use rand. You will also find the built-in function floor useful for obtaining integers. To make sure that your result is indeed uniformly distributed, test the output of the function by using the built-in function hist, which plots a histogram.
My code is as follows,
function [r] = randomness(limit,n,m)
r= 1+floor(rand(n,m).*(limit-1))
hist(randomness, 1:limit)
end
It keeps giving me an error for the arguments (20,500000,1) and i am not sure why.I have tried using ceil and fix instead of floor, but to little or no avail.

Best Answer

hist(r, 1:limit);
You inadvertently used randomness in your hist call, so MATLAB tried a recursive call with no arguments, hence the error.
You should re-check your algorithm, however, since it currently doesn't produce any values at "limit" and the instructions say "inclusive".