# randcycle

``````..  randcycle([rng,] n)

Construct a random cyclic permutation of length ``n``. The optional ``rng``
argument specifies a random number generator, see :ref:`Random Numbers
<random-numbers>`.``````

## Examples

In the Julia programming language, the function `randcycle([rng,] n)` generates a random cyclic permutation of length `n`. The optional `rng` argument specifies a random number generator.

``````jldoctest
julia> randcycle(5)
5-element Array{Int64,1}:
4
1
3
2
5``````

This example generates a random cyclic permutation of length 5. Each element in the returned array represents the position of the corresponding element in the original sequence after the permutation.

``````jldoctest
julia> rng = MersenneTwister(1234);  # Initialize random number generator
julia> randcycle(rng, 4)
4-element Array{Int64,1}:
3
2
1
4``````

In this example, a specific random number generator (`MersenneTwister`) is used to generate the random cyclic permutation. The permutation is of length 4.

Note: The `rng` argument is optional. If not provided, the default random number generator is used.

``````jldoctest
julia> randcycle(0)
0-element Array{Int64,1}``````

When `n` is 0, an empty array is returned since there are no elements to permute.

``````jldoctest
julia> randcycle(1)
1-element Array{Int64,1}:
1``````

If `n` is 1, the returned array will always have a single element with value 1, as there is only one element in the permutation.

``````jldoctest
julia> randcycle(10^6)
1000000-element Array{Int64,1}:
836288
419568
995448
550716
64320
342540
287892
136836
532452
593652
258240
...``````

This example demonstrates generating a large random cyclic permutation of length 10^6. The permutation is represented as a 1D array with the positions of the elements.