function p = rand_perm ( n )

%*****************************************************************************80
%
%% RAND_PERM returns a random permutation of integers 1 to N
%
  p = 1 : n;

  for i = 1 : n - 1

    j = rand_int2 ( i, n );

    t = p(j);
    p(j) = p(i);
    p(i) = t;

  end

  return
end
function j = rand_int2 ( i1, i2 )

%*****************************************************************************80
%
%% RAND_INT2 returns a random integer between I1 and I2.
%
  j = i1 + floor ( ( i2 + 1 - i1 ) * rand ( ) );

  return
end

