% RANDGRPSIZE - Script to generate random group sizes, totaling 100.  The max size
% for one group is 60.


% Initialize the matrix.
GS = [];

% Initialize k; the numbers generated (group sizes) will be between 1 and k 
k = 99;

% Loop will generate numbers until there are not less than 100.
while sum(GS) < 100
    
    % Each time through, i will be the number generated.  The min function
    % ensures that 60 is the max possible value.  K * rand + 1 forces the 
    % number to be between 1 and k.
    i = min(round(k * rand + 1),60);
    
    % Decreases k by i, so that next time through the loop, the max value 
    % will be between the current total and 100.
    k = k-i;
    
    % Build the GS (group size) matrix piece-wise.
    GS = [GS i];
    
end                     % End loop.

GS;
