% Copying and distribution of this file, with or without modification,
% are permitted in any medium without royalty provided this notice is
% preserved.  This file is offered as-is, without any warranty.
%
% If you modify it and use it with MATLAB (that is proprietary), please
% check compatibility with GNU Octave (that is free/libre software).


function matrix = random_stochastic_matrix_in_lines(nb_lines,
						    nb_columns,
						    fill_percentage = 0.1)
  matrix = zeros(nb_lines, nb_columns);
  for line = 1 : nb_lines
    remaining_value = 1.0;
    nb_columns_filled = ceil(nb_columns * fill_percentage);
    
    for a = 1 : nb_columns_filled -1
      column = random_null_column_in_line_of_matrix_2d(matrix, line);
      value = mod(rand(), remaining_value);
      remaining_value = remaining_value - value;
      matrix(line, column) = value;
    end
    
    column = random_null_column_in_line_of_matrix_2d(matrix, line);
    matrix(line, column) = remaining_value;
  end
end
