function x = negative_binomial_sample ( a, b )

%*****************************************************************************80
%
%% negative_binomial_sample() samples the Negative Binomial PDF.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    12 January 2021
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer A, a parameter of the PDF.
%    0 <= A.
%
%    real B, a parameter of the PDF.
%    0 < B <= 1.
%
%  Output:
%
%    integer X, a sample of the PDF.
%
  if ( b == 1.0 )
    x = a;
    return
  elseif ( b == 0.0 )
    x = Inf;
    return
  end

  x = 0;
  num_success = 0;

  while ( num_success < a )

    x = x + 1;
    r = rand ( 1, 1 );

    if ( r <= b )
      num_success = num_success + 1;
    end

  end

  return
end
