function rnglib_test03 ( )

%*****************************************************************************80
%
%% rnglib_test03() demonstrates how the key can be reset to its initial or last value.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    28 March 2013
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'RNGLIB_TEST03\n' );
  fprintf ( 1, '  r8_UNI_01 ( ) returns a random real number\n' );
  fprintf ( 1, '  in [0,1] using the current generator.\n' );
%
%  Initialize the package.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, '  INITIALIZE initializes the random number generator.\n' );
  fprintf ( 1, '  It only needs to be called once before using the package.\n' );

  initialize ( );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  INIT_GENERATOR can reset the key to the initial value,\n' );
  fprintf ( 1, '  the last (previous) value, or a new key.\n' );
%
%  Set the current generator index to 17.
%
  g = 17;
  cgn_set ( g );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Current generator index = %d\n', g );
%
%  Force the current generator to begin at its initial key.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, '  INIT_GENERATOR ( 0 ) starts at the initial key.\n' );

  init_generator ( 0 );

  fprintf ( 1, '\n' );
  fprintf ( 1, '   I    r8_UNI_01 ( )\n' );
  fprintf ( 1, '\n' );
  for i = 1 : 10
    u = r8_uni_01 ( );
    fprintf ( 1, '  %2d  %14.6g\n', i, u );
  end

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Calling INIT_GENERATOR ( 0 ) again restarts\n' );
  fprintf ( 1, '  at the initial key.\n' );

  init_generator ( 0 );

  fprintf ( 1, '\n' );
  fprintf ( 1, '   I    r8_UNI_01 ( )\n' );
  fprintf ( 1, '\n' );
  for i = 1 : 10
    u = r8_uni_01 ( );
    fprintf ( 1, '  %2d  %14.6g\n', i, u );
  end

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Calling INIT_GENERATOR ( 2 ) restarts\n' );
  fprintf ( 1, '  at a new "far ahead" key.\n' );

  init_generator ( 2 );

  fprintf ( 1, '\n' );
  fprintf ( 1, '   I    r8_UNI_01 ( )\n' );
  fprintf ( 1, '\n' );
  for i = 1 : 10
    u = r8_uni_01 ( );
    fprintf ( 1, '  %2d  %14.6g\n', i, u );
  end

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Calling INIT_GENERATOR ( 1 ) restarts\n' );
  fprintf ( 1, '  at the last key (in this case, the "far ahead"\n' );
  fprintf ( 1, '  key specified on the previous call.)\n' );

  fprintf ( 1, '\n' );
  fprintf ( 1, '   I    r8_UNI_01 ( )\n' );
  fprintf ( 1, '\n' );
  for i = 1 : 10
    u = r8_uni_01 ( );
    fprintf ( 1, '  %2d  %14.6g\n', i, u );
    if ( mod ( i, 3 ) == 0 )
      init_generator ( 1 );
      fprintf ( 1, '  (Reset to last key)\n' );
    end
  end

  return
end
