function sons = offspring ( zero, one, two, three, four, five, six )

%*****************************************************************************80
%
%% OFFSPRING randomly determines the number of sons born.
%
%  Discussion:
%
%    This is a utility functioned needed by BOOM.M.
%
%  Modified:
%
%    27 January 2018
%
%  Author:
%
%    Paul Nahin
%
%  Reference:
%
%    Paul Nahin,
%    Digital Dice: Computational Solutions to Practical Probability Problems,
%    Princeton, 2008,
%    ISBN: 978-0-691-15821-1.
%
%  Input parameters:
%
%    Input, real ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, the probability
%    of having no more than 0, 1, 2, 3, 4, 5, or 6 sons.
%
%    Output, integer SONS, a randomly chosen number of sons.
%
  luck = rand ( );

  if ( luck < zero )
    sons = 0;
  elseif ( luck < one )
    sons = 1;
  elseif ( luck < two )
    sons = 2;
  elseif ( luck < three )
    sons = 3;
  elseif ( luck < four )
    sons = 4;
  elseif ( luck < five )
    sons = 5;
  elseif ( luck < six )
    sons = 6;
  else
    sons = 7;
  end

  return
end

