f = [ 150, 75, 10, 75, 180, 210 ];
n = length ( f );
m = sum ( f );
p = f / m;
c = cumsum ( p );

bins = zeros ( 1, n );
for i = 1 : m
  r = rand ( );
  for j = 1 : n
    if ( r < c(j) )
      bins(j) = bins(j) + 1;
      break;
    end
  end
end

bar ( 1:n, f );
grid on
xlabel ( '<-- Outcomes -->' );
ylabel ( '<-- Frequency -->' );
title ( 'Frequencies for loaded die', 'Fontsize', 24 );
print ( '-djpeg', 'loaded_frequency.jpg' );

bar ( 1:n, bins );
grid on
xlabel ( '<-- Outcomes -->' );
ylabel ( '<-- Frequency -->' );
title ( 'Simulate a loaded die', 'Fontsize', 24 );
print ( '-djpeg', 'loaded_simulation.jpg' );
