function ranlib_test_gengam ( phrase )

%*****************************************************************************80
%
%% ranlib_test_gengam() tests gengam().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    01 April 2013
%
%  Author:
%
%    John Burkardt
%
  n = 1000;

  fprintf ( 1, '\n' );
  fprintf ( 1, 'RANLIB_TEST_GENGAM\n' );
  fprintf ( 1, '  Test GENGAM,\n' );
  fprintf ( 1, '  which generates Gamma deviates.\n' );
%
%  Initialize the generators.
%
  initialize ( );
%
%  Set the keys based on the phrase.
%
  [ key1, key2 ] = phrtsd ( phrase );
%
%  Initialize all generators.
%
  set_initial_key ( key1, key2 );
%
%  Select the parameters at random within a given range.
%
  low = 1.0;
  high = 10.0;
  a = genunf ( low, high );

  low = 1.0;
  high = 10.0;
  r = genunf ( low, high );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  N = %d\n', n );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Parameter values:\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  A = %g\n', a );
  fprintf ( 1, '  R = %g\n', r );
%
%  Generate N samples.
%
  for i = 1 : n
    array(i) = gengam ( a, r );
  end
%
%  Compute statistics on the samples.
%
  [ av, var, xmin, xmax ] = stats ( array, n );
%
%  Request expected value of statistics for this distribution.
%
  pdf = 'gam';
  param(1) = a;
  param(2) = r;
  [ avtr, vartr ] = trstat ( pdf, param );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Sample data range:          %14.6g  %14.6g\n', xmin, xmax );
  fprintf ( 1, '  Sample mean, variance:      %14.6g  %14.6g\n', av,   var );
  fprintf ( 1, '  Distribution mean, variance %14.6g  %14.6g\n', avtr, vartr );

  return
end
