function [ value, seed ] = birthday_sample ( n, seed )

%*****************************************************************************80
%
%% BIRTHDAY_SAMPLE samples the Birthday Concurrence PDF.
%
%  Discussion:
%
%    The probability is the probability that the N-th person is the
%    first one to match a birthday with someone earlier.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    09 March 2016
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer N, the number of people whose birthdays have been
%    disclosed.
%
%    Input, integer SEED, a seed for the random number generator.
%
%    Output, integer VALUE,
%    * 1 if the first N-1 people had distinct
%      birthdays, but person N had a birthday in common with a previous person,
%    * 0 otherwise.
%
%    Output, integer SEED, a seed for the random number generator.
%
  if ( n < 1 )
    value = 0;
    return
  end

  if ( 365 < n )
    value = 1;
    return
  end
%
%  Choose N birthdays at random.
%
  [ b, seed ] = i4vec_uniform_ab ( n, 1, 365, seed );
%
%  Are the first N-1 birthdays unique?
%
  u1 = i4vec_unique_count ( n - 1, b(1:n-1) );

  if ( u1 < n - 1 )
    value = 0;
    return
  end
%
%  Does the N-th birthday match an earlier one?
%
  u2 = i4vec_unique_count ( n, b(1:n) );

  if ( u2 == n - 1 )
    value = 1;
  else
    value = 0;
  end

  return
end

