Random number gerator problem
Mostrar comentarios más antiguos
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.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Annotations en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
