Random Generation#
Symmetria provides a way to generate random permutation.
You can use the random generation of permutations in the following way
import symmetria
permutations = symmetria.random_generator(algorithm="lexicographic", degree=3)
If you don’t want to have a generator and you want to just have a singular random permutation you can use write
import symmetria
permutation = symmetria.random(algorithm="lexicographic", degree=3)
A list of implemented algorithms to generate permutations:
Algorithm |
Description |
Reference |
|---|---|---|
|
A permutation is generated by choosing the integer uniformly. |
|
|
The permutations are generate following the Steinhaus-Johnson-Trotter algorithm. |
The API of the method is given as following:
- symmetria.generators.random.api.random_generator(degree: int, algorithm: str = 'random') Generator[Permutation, None, None][source]#
Generate random permutations of the given degree based on the chosen algorithm.
The method generates random permutations of the given degree using the specified algorithm.
- Parameters:
degree (int) – The degree of the permutations to be generated. Must be a non-zero positive integer.
algorithm (str, optional) – The algorithm to use for generating permutations. Default is
random.
- Returns:
An infinite generator yielding permutations.
- Return type:
Generator[Permutation, None, None]
- Raises:
ValueError – If the algorithm is not supported or the degree is invalid.
- Examples:
>>> from symmetria import random_generator ... >>> permutations = random_generator(degree=3, algorithm="fisher-yates")
- symmetria.generators.random.api.random_permutation(degree: int, algorithm: str = 'random') Permutation[source]#
Generate a random permutation of the given degree based on the chosen algorithm.
The method generate a random permutation of the given degree using the specified algorithm.
- Parameters:
degree (int) – The degree of the permutation to be generated. Must be a non-zero positive integer.
algorithm (str, optional) – The algorithm to use for generating permutations. Default is
random.
- Returns:
A permutation object.
- Return type:
- Raises:
ValueError – If the algorithm is not supported or the degree is invalid.
- Examples:
>>> from symmetria import random_permutation ... >>> permutation = random_permutation(degree=3, algorithm="fisher-yates")