You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: sample_hist.m
    path of file: ./repos/lrslibrary/libs/+lightspeed
    
    the code of the file until where you have to start completion: function h = sample_hist(p, n)
%SAMPLE_HIST     Sample from a multinomial distribution.
% SAMPLE_HIST(P,N) returns a random matrix of counts, same size as P, 
% whose column sums are all N.  Column j is sampled from a multinomial with
% the probabilities p(:,j).
%
% Example:
%   sample_hist([0.2 0.4; 0.8 0.6],100)

% The advantage of this alg is that the running time grows slowly with n.
% It is the same alg used by BUGS.

    
function h = sample_hist(p, n)
%SAMPLE_HIST     Sample from a multinomial distribution.
% SAMPLE_HIST(P,N) returns a random matrix of counts, same size as P, 
% whose column sums are all N.  Column j is sampled from a multinomial with
% the probabilities p(:,j).
%
% Example:
%   sample_hist([0.2 0.4; 0.8 0.6],100)

% The advantage of this alg is that the running time grows slowly with n.
% It is the same alg used by BUGS.
% If n is very small then it is faster to just take n samples from p.

if nargin < 2
  n = 1;
end