Learn R Programming

cayleyR (version 0.2.1)

generate_state: Generate Reachable Random State

Description

Generates a random state reachable from 1:n by applying random operations (L, R, X). Guarantees the result is in the same connected component as the starting state.

Usage

generate_state(n, k = n, n_moves = 25L, moves = c("1", "2", "3"))

Value

Integer vector representing a reachable permutation state

Arguments

n

Integer, the size of the permutation

k

Integer, parameter for reverse_prefix operation

n_moves

Integer, number of random operations to apply (default 25)

moves

Character vector, allowed operations (default c("1", "2", "3"))

Examples

Run this code
set.seed(42)
generate_state(10, k = 4)
generate_state(10, k = 4, n_moves = 100)

Run the code above in your browser using DataLab