function x = binomial_sample ( a, b )

%*****************************************************************************80
%
%% binomial_sample() samples the Binomial PDF.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    07 April 2022
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    William Kennedy and James Gentle,
%    Algorithm BU,
%    Statistical Computing,
%    Dekker, 1980.
%
%  Input:
%
%    integer A, the number of trials.
%    1 <= A.
%
%    real B, the probability of success on one trial.
%    0.0 <= B <= 1.0.
%
%  Output:
%
%    integer X, a sample of the PDF.
%
  x = 0;

  for i = 1 : a

    u = rand ( 1, 1 );

    if ( u <= b )
      x = x + 1;
    end

  end

  return
end
