function A = graph_adj_random ( node_num, prob )

%*****************************************************************************80
%
%% graph_adj_random() generates a random graph on a given number of nodes.
%
%  Discussion:
%
%    The user specifies the probability P that an edge will be generated
%    between any pair of nodes.
%
%    ADJ(I,J) is nonzero if there is an edge from node I to node J.  
%    ADJ(I,I) will always be 0.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    07 March 2022
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer node_num: the number of nodes.
%
%    real prob: the probability that an edge will
%    be generated between any given pair of nodes.
%
%  Output:
%
%    integer A(node_num,node_num): the adjacency matrix.  
%
  if ( prob < 0.0 | 1.0 < prob )
    fprintf ( 1, '\n' );
    fprintf ( 1, 'graph_adj_random(): Fatal error!\n' );
    fprintf ( 1, '  Input probability PROB is not between 0 and 1.\n' );
    error ( 'graph_adj_random(): Fatal error!' );
  end

  P = rand ( node_num, node_num );
  P = tril ( P );
  P = ( P + transpose ( P ) );

  A = zeros ( node_num, node_num );
  one = find ( P <= prob );
  A(one) = 1;

% for i = 1 : node_num
%   A(i,i) = 0;
% end

  return
end
