function [ determ, seed ] = ref_random_determinant ( n, prob, key )

%*****************************************************************************80
%
%% REF_RANDOM_DETERMINANT: determinant of a REF_RANDOM matrix.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    08 July 2011
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N, the order of the matrix.
%
%    real PROB, the probability that the 1 in the next
%    row will be placed as early as possibly.
%    Setting PROB = 1 forces the 1 to occur immediately, setting
%    PROB = 0 forces the entire matrix to be zero.  A more reasonable
%    value might be PROB = 0.8 or 0.9.
%
%    integer KEY, a positive value that selects the data.
%
%  Output:
%
%    real DETERM, the determinant.
%
  determ = 1.0;

  rng ( key );

  jprev = 0;

  for i = 1 : n

    jnew = 0;

    for j = 1 : n

      if ( j <= jprev )

      elseif ( jnew == 0 )
        temp = rand ( 1, 1 );
        if ( temp <= prob )
          jnew = j;
        else

        end
      else
        temp = rand ( 1, 1 );
      end

    end

    if ( jnew ~= i )
      determ = 0.0;
    end

    if ( jnew == 0 )
      jnew = n + 1;
    end

    jprev = jnew;

  end

  return
end
