function x = discrete_sample ( a, b )

%*****************************************************************************80
%
%% discrete_sample() samples the Discrete PDF.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    07 September 2004
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer A, the number of probabilities assigned.
%
%    real B(A), the relative probabilities of
%    outcomes 1 through A.  Each entry must be nonnegative.
%
%  Output:
%
%    integer X, a sample of the PDF.
%
  b_sum = sum ( b(1:a) );

  cdf = rand ( 1, 1 );

  x = discrete_cdf_inv ( cdf, a, b );

  return
end
