function [ a, seed ] = r8pbl_random ( n, ml, seed )

%*****************************************************************************80
%
%% R8PBL_RANDOM randomizes a R8PBL matrix.
%
%  Discussion:
%
%    The R8PBL storage format is for a symmetric positive definite band matrix.
%
%    To save storage, only the diagonal and lower triangle of A is stored,
%    in a compact diagonal format that preserves columns.
%
%    The diagonal is stored in row 1 of the array.
%    The first subdiagonal in row 2, columns 1 through ML.
%    The second subdiagonal in row 3, columns 1 through ML-1.
%    The ML-th subdiagonal in row ML+1, columns 1 through 1.
%
%    The matrix returned will be positive definite, but of limited
%    randomness.  The off diagonal elements are random values between
%    0 and 1, and the diagonal element of each row is selected to
%    ensure strict diagonal dominance.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    16 February 2005
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer N, the order of the matrix.
%    N must be positive.
%
%    Input, integer ML, the number of subdiagonals in the matrix.
%    ML must be at least 0 and no more than N-1.
%
%    Input, integer SEED, a seed for the random number generator.
%
%    Output, real A(ML+1,N), the R8PBL matrix.
%
%    Output, integer SEED, a seed for the random number generator.
%
  a = zeros ( ml + 1, n );
%
%  Set the off diagonal values.
%
  for i = 1 : n
    for j = max ( 1, i - ml ) : i - 1
      [ a(i-j+1,j), seed ] = r8_uniform_01 ( seed );
    end
  end
%
%  Set the diagonal values.
%
  for i = 1 : n

    sum2 = 0.0;

    jlo = max ( 1, i - ml );
    for j = jlo : i - 1
      sum2 = sum2 + abs ( a(i-j+1,j) );
    end

    jhi = min ( i + ml, n );
    for j = i+1 : jhi
      sum2 = sum2 + abs ( a(j-i+1,i) );
    end

    [ r, seed ] = r8_uniform_01 ( seed );

    a(1,i) = ( 1.0 + r ) * ( sum2 + 0.01 );

  end

  return
end
