function rng_test ( )

%*****************************************************************************80
%
%% rng_test() tests rng().
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    05 September 2012
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'rng_test():\n' );
  fprintf ( 1, '  Test the random number function rng().\n' );
%
%  No initialization.
%
  for i = 1 : 5
    rng_test01 ( );
  end

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Skip remaining tests, since rng() is not fully\n' );
  fprintf ( 1, '  implemented in Octave.\n' );
  return
%
%  Same initialization.
%
  key = 123456789;
  for i = 1 : 5
    rng_test02 ( key );
    key = key;
  end
%
%  Varying initialization.
%
  key = 123456789;
  for i = 1 : 5
    rng_test02 ( key );
    key = 123456789 + mod ( i, 3 );
  end
%
%  Random initialization.
%
  for i = 1 : 5
    rng_test03 ( );
  end
%
%  Save and restore state.
%
  rng_test04 ( );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'rng_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );

  return
end
function rng_test01 ( )

%*****************************************************************************80
%
%% rng_test01() calls rand() with no initialization.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    05 September 2012
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'rng_test01():\n' );
  fprintf ( 1, '  Call rand() with no initialization:\n' );
  fprintf ( 1, '\n' );

  for i = 1 : 5
    r = rand ( );
    fprintf ( 1, '  %d  %g\n', i, r );
  end

  return
end
function rng_test02 ( key )

%*****************************************************************************80
%
%% rng_test02() initializes random number generator with key.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    05 September 2012
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'rng_test02():\n' );
  fprintf ( 1, '  Initialize random number generation with rng(%d):\n', key );
  fprintf ( 1, '\n' );

  rng ( key );

  for i = 1 : 5
    r = rand ( );
    fprintf ( 1, '  %d  %g\n', i, r );
  end

  return
end
function rng_test03 ( )

%*****************************************************************************80
%
%% rng_test03() randomly initializes the random number generator.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    05 September 2012
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'rng_test03():\n' );
  fprintf ( 1, '  Randomly initialize with rng(''shuffle''):\n' );
  fprintf ( 1, '\n' );

  rng ( 'shuffle' );

  for i = 1 : 5
    r = rand ( );
    fprintf ( 1, '  %d  %g\n', i, r );
  end

  return
end
function rng_test04 ( )

%*****************************************************************************80
%
%% rng_test04() saves the state and restores it later.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    05 September 2012
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'rng_test04():\n' );
  fprintf ( 1, '  Save and restore the rng() state:\n' );
  fprintf ( 1, '\n' );

  s = rng ( );

  for i = 1 : 5
    r = rand ( );
    fprintf ( 1, '  %d  %g\n', i, r );
  end

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Restoring state:\n' );
  fprintf ( 1, '\n' );

  rng ( s );

  for i = 1 : 5
    r = rand ( );
    fprintf ( 1, '  %d  %g\n', i, r );
  end
  return
end

