function x = loadedDice(w,n)
% Returns a vector x of n random dice throws, with values 1 to 6
% Input
%   w : vector of weights of each result (1 to 6)
%   n : number of values (dice throws) to be returned
% Output
%   x : row vector of n throw results (values 1 to 6)
% Usage
%   x = loadedDice([0.16 0.16 0.16 0.16 0.16 0.20],100)
% Author
%   Jose M Soler. Nov.2010

% Find accumulated probabilities
pSum = cumsum(w) / sum(w);    % cumsum finds the accumulated sums

% Find throw results
x = zeros(1,n);               % allocate memory for vector x
for i = 1:n                   % loop on n throws
    x(i) = find(rand<pSum,1); % first integer x such that rand<pSum(x)
end

end