function randi_test ( )

%*****************************************************************************80
%
%% randi_test() shows how random integers are generated.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    14 February 2013
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'randi_test():\n' );
  fprintf ( 1, '  randi() generates random integers.\n' );

  randi_test01 ( );

  randi_test02 ( );

  key = 123456789;
  randi_test03 ( key );

  key = 987654321;
  randi_test03 ( key );

  key = 123456789;
  randi_test03 ( key );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'randi_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );

  return
end
function randi_test01 ( )

%*****************************************************************************80
%
%% randi_test01() simply calls the random integer generator a few times.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    14 February 2013
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'randi_test01():\n' );
  fprintf ( 1, '  In MATLAB, random integers are generated by calling randi():\n' );
  fprintf ( 1, '  The maximum value is specified as IMAX.\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  A = randi ( imax, 1, 1 ) a random scalar value between 1 and IMAX.\n' );
  fprintf ( 1, '  B = randi ( imax, 5, 1 ) a random column vector of 5 entries.\n' );
  fprintf ( 1, '  C = randi ( imax, 1, 5 ) a random row vector of 5 entries.\n' );
  fprintf ( 1, '  D = randi ( imax, 3, 4 ) a 3 by 4 random matrix.\n' );
  fprintf ( 1, '  E = randi ( imax, 5, 5 ) a 5 by 5 random matrix.\n' );

  a = randi ( 9, 1, 1 )
  b = randi ( 9, 5, 1 )
  c = randi ( 9, 1, 5 )
  d = randi ( 4, 3, 4 )
  e = randi ( 4, 5, 5 )

  return
end
function randi_test02 ( )

%*****************************************************************************80
%
%% randi_test02() specifies the lower and upper limits.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    14 February 2013
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'randi_test02():\n' );
  fprintf ( 1, '  randi() allows the user to specify the numeric range.\n' );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  A = randi ( [ 5,    10 ],  1, 1 ) a random scalar value.\n' );
  fprintf ( 1, '  B = randi ( [ 7,     8 ], 10, 1 ) a random column vector of 5 entries.\n' );
  fprintf ( 1, '  C = randi ( [ -1,   +1 ],  1, 5 ) a random row vector of 5 entries.\n' );
  fprintf ( 1, '  D = randi ( [ -5,   +5 ],  3, 4 ) a 3 by 4 random matrix.\n' );
  fprintf ( 1, '  E = randi ( [ 100, 200 ],  5, 5 ) a 5 by 5 random matrix.\n' );

  a = randi ( [   5,  10 ], 1, 1 )
  b = randi ( [   7,   8 ], 10, 1 )
  c = randi ( [  -1,  +1 ], 1, 5 )
  d = randi ( [  -5,  +5 ], 3, 4 )
  e = randi ( [ 100, 200 ], 5, 5 )

  return
end
function randi_test03 ( key )

%*****************************************************************************80
%
%% randi_test03() sets the key before calling randi().
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    13 February 2013
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'randi_test03():\n' );
  fprintf ( 1, '  By setting the random number key, you can control\n' );
  fprintf ( 1, '  how the random number sequence begins.\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  This is NOT implemented in Octave.\n' );
  return

  fprintf ( 1, '  The command "rng ( 123456789 )" sets the key to 123456789.\n' );

  rng ( key );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  key has been set to %d\n', key );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Now generate 5 random values.\n' );

  for i = 1 : 5
    a = randi (  [ 1, 100 ], 1, 1 );
    fprintf ( 1, '  randi([1,100],1,1) = %g\n', a );
  end

  rng ( key );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  key has been reset to %d\n', key );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Now generate 5 more random values.\n' );

  for i = 1 : 5
    a = randi ( [ 1, 100 ], 1, 1 );
    fprintf ( 1, '  randi([1,100],1,1) = %g\n', a );
  end

  return
end

