function u = unicycle_random ( n )

%*****************************************************************************80
%
%% unicycle_random() selects a random unicycle of N objects.
%
%  Discussion:
%
%    The routine assumes the objects are labeled 1, 2, ... N.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    08 July 2021
%
%  Author:
%
%    John Burkardt.
%
%  Reference:
%
%    Albert Nijenhuis, Herbert Wilf,
%    Combinatorial Algorithms for Computers and Calculators,
%    Second Edition,
%    Academic Press, 1978,
%    ISBN: 0-12-519260-6,
%    LC: QA164.N54.
%
%  Input:
%
%    integer N, the number of objects to be permuted.
%
%  Output:
%
%    integer U(N), a unicycle in sequence form.
%
  u = 1 : n;

  for i = 2 : n
    j = randi ( [ i, n ], 1 );
    t = u(i);
    u(i) = u(j);
    u(j) = t;
  end

  return
end
