In this Matlab code, I'm trying to generate a random vector of int and dividing with their sum to make it behave like probability values. But sometimes(not always) its not summing upto 1. Is it a floating point precision issue ?? How can I fix it ?
for I = 1:5
A = randi([1,10],[1,10]);
% Just get a 10 length vector of random int
A = A/sum(A);
% Make the vector normalize to
% behave like probability values
if sum(A)~=1
% should sum to one
% but sometimes its not
disp(['Not equal to 1', sum(A)]);
else
disp('Equal to 1');
end
end