function value = birthday_sample ( n )

%*****************************************************************************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 MIT license.
%
%  Modified:
%
%    07 April 2022
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N, the number of people whose birthdays have been
%    disclosed.
%
%  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.
%
  if ( n < 1 )
    value = 0;
    return
  end

  if ( 365 < n )
    value = 1;
    return
  end
%
%  Choose N birthdays at random.
%
  b = randi ( [ 1, 365 ], n );
%
%  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

