function init_generator ( t )

%*****************************************************************************80
%
%% INIT_GENERATOR sets the current generator to initial, last or new seed.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    31 March 2013
%
%  Author:
%
%    Original Pascal version by Pierre L'Ecuyer, Serge Cote.
%    MATLAB version by John Burkardt.
%
%  Reference:
%
%    Pierre LEcuyer, Serge Cote,
%    Implementing a Random Number Package with Splitting Facilities,
%    ACM Transactions on Mathematical Software,
%    Volume 17, Number 1, March 1991, pages 98-111.
%
%  Parameters:
%
%    Input, integer T, the seed type:
%    0, use the seed chosen at initialization time.
%    1, use the last seed.
%    2, use a new seed set 2^30 values away.
%
  a1_w = 1033780774;
  a2_w = 1494757890;
  m1 = 2147483563;
  m2 = 2147483399;
%
%  Check whether the package must be initialized.
%
  if ( ~ initialized_get ( ) )
    fprintf ( 1, '\n' );
    fprintf ( 1, 'INIT_GENERATOR - Note:\n' );
    fprintf ( 1, '  Initializing RNGLIB package.\n' );
    initialize ( );
  end
%
%  Get the current generator index.
%
  g = cgn_get ( );
%
%  0: Restore the initial seed.
%
  if ( t == 0 )

    [ ig1, ig2 ] = ig_get ( g );
    lg1 = ig1;
    lg2 = ig2;
    lg_set ( g, lg1, lg2 );
%
%  1: Restore the last seed.
%
  elseif ( t == 1 )

    [ lg1, lg2 ] = lg_get ( g );
%
%  Advance to a new seed.
%
  elseif ( t == 2 )

    [ lg1, lg2 ] = lg_get ( g );
    lg1 = multmod ( a1_w, lg1, m1 );
    lg2 = multmod ( a2_w, lg2, m2 );
    lg_set ( g, lg1, lg2 );

  else

    fprintf ( 1, '\n' );
    fprintf ( 1, 'INIT_GENERATOR - Fatal error!\n' );
    fprintf ( 1, '  Input parameter T out of bounds.\n' );
    error ( 'INIT_GENERATOR - Fatal error!' );

  end
%
%  Store the new seed.
%
  cg1 = lg1;
  cg2 = lg2;
  cg_set ( g, cg1, cg2 );

  return
end
