function x = inverse_gaussian_sample ( a, b )

%*****************************************************************************80
%
%% inverse_gaussian_sample() samples the Inverse Gaussian PDF.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    12 September 2004
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real A, B, the parameters of the PDF.
%    0.0 < A,
%    0.0 < B.
%
%  Output:
%
%    real X, a sample of the PDF.
%
  phi = b / a;
  z = randn ( 1, 1 );
  y = z * z;

  t = 1.0 + 0.5 * ( y - sqrt ( 4.0 * phi * y + y * y ) ) / phi;
  u = rand ( 1, 1 );

  if ( u * ( 1.0 + t ) <= 1.0 )
    x = a * t;
  else
    x = a / t;
  end

  return
end
