Skip to contents

Builds the cyclic Latin square then permutes rows, columns, and symbols. Uniform over a subset of Latin squares (not all).

Usage

mrm_random_latin(k, seed = 42L)

Arguments

k

Side length.

seed

RNG seed.

Value

A k x k integer matrix (codes 0..k-1) with row names R1..Rk and column names C1..Ck. Each code appears exactly once per row and per column.

Examples

# 4 x 4 random Latin square: each of {0, 1, 2, 3} appears once
# per row and per column.
mrm_random_latin(k = 4, seed = 42L)
#>    C1 C2 C3 C4
#> R1  2  0  1  3
#> R2  3  1  2  0
#> R3  0  2  3  1
#> R4  1  3  0  2

# Reproducible across runs with the same seed:
identical(
  mrm_random_latin(5, seed = 7),
  mrm_random_latin(5, seed = 7)
)
#> [1] TRUE