function rnglib_test04 ( )

%*****************************************************************************80
%
%% rnglib_test04() demonstrates the use of multiple streams.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    05 August 2013
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'RNGLIB_TEST04\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, '  Let us call generators #3, #6 and #9.\n' );
%
%  Use three separate generators, 3, 6 and 9.
%  Force them to start at their initial keys.
%
  g(1) = 3;
  g(2) = 6;
  g(3) = 9;
  fprintf ( 1, '\n' );
  for i = 1 : 3
    fprintf ( 1, '  Initialize generator %d\n', g(i) );
    cgn_set ( g(i) );
    init_generator ( 0 );
  end
%
%  Call the generators in the order 3, 6, 9.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, '   I    r8_UNI_01 ( 3 )  r8_UNI_01 ( 6 )  r8_UNI_01 ( 9 )\n' );
  fprintf ( 1, '\n' );
  for i = 1 : 10
    for j = 1 : 3
      cgn_set ( g(j) );
      u(j) = r8_uni_01 ( );
    end
    fprintf ( 1, '  %2d  %14.6g  %14.6g  %14.6g\n', i, u(1:3) );
  end
%
%  Restart the generators at their initial keys.
%
  g(1) = 6;
  g(2) = 9;
  g(3) = 3;
  fprintf ( 1, '\n' );
  for i = 1 : 3
    fprintf ( 1, '  Reinitialize generator %d\n', g(i) );
    cgn_set ( g(i) );
    init_generator ( 0 );
  end
%
%  Call them in a different order, same result.

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

  return
end
