Skip to content

Generators

Random data generators shipped with the Cyber Range Kyoushi Generator CLI.

Random (random)

Generator exposing the python random library

See https://docs.python.org/3/library/random.html

Examples:

foo: bar
time: "{{ random.randint(0, 11) }}:{{ random.randint(0, 59) }}"

cr_kyoushi.generator.core.RandomGenerator.create(self, seed_store)

Creates a Random object and initialized with the next seed from the seed store.

Parameters:

Name Type Description Default
seed_store SeedStore

The seed store to use for getting the seed

required

Returns:

Type Description
Random

Python Random object

Source code in generator/core.py
def create(self, seed_store: SeedStore) -> Random:
    """Creates a Random object and initialized with the next seed from the seed store.

    Args:
        seed_store: The seed store to use for getting the seed

    Returns:
        Python Random object
    """
    return Random(seed_store.next())

Faker (faker)

Generator exposing a faker object

The created faker object is configured to support all available locales, but will default to en_UK, en_US (in order). A locale can be specified through the array access.

Examples:

    user:
        name: "{{ faker["jp_JP"].name() }}"
        title: "{{ faker.suffix() }}"
        address: "{{ faker["de_AT"].address() }}"

See https://faker.readthedocs.io/en/master/providers.html

cr_kyoushi.generator.core.FakerGenerator.create(self, seed_store)

Creates a faker object initialized with a seed from the given seed store.

Parameters:

Name Type Description Default
seed_store SeedStore

The seed store to use

required

Returns:

Type Description
Faker

Faker object with all locales available

Source code in generator/core.py
def create(self, seed_store: SeedStore) -> Faker:
    """Creates a faker object initialized with a seed from the given seed store.

    Args:
        seed_store: The seed store to use

    Returns:
        Faker object with all locales available
    """
    locales = ["en_UK", "en_US"]
    faker = Faker(locale=locales)
    Faker.seed(seed_store.next())
    return faker

Numpy (numpy)

Generator exposing the numpy libraries random API

See https://numpy.org/doc/stable/reference/random/generator.html

Examples:

    {% set company_names = ["ACME", "XYZ Ltd.", "Umbrella CORP.", "Mom and Pop", "Contoso", "Oceanic Airlines"] %}
    companies:
    {% for company in numpy.choices(company_names, size=3) %}
        - name: {{ company }}
          address: {{ faker.address() }}
    {% endfor %}

cr_kyoushi.generator.core.NumpyGenerator.create(self, seed_store)

Creates a numpy RandomGenerator object initialized with a seed from the given seed store.

Parameters:

Name Type Description Default
seed_store SeedStore

The seed store to use

required

Returns:

Type Description
Generator

numpy RandomGenerator object

Source code in generator/core.py
def create(self, seed_store: SeedStore) -> NumpyRandomGenerator:
    """Creates a numpy RandomGenerator object initialized with a seed from the given seed store.

    Args:
        seed_store: The seed store to use

    Returns:
        numpy RandomGenerator object
    """
    return numpy_default_rng(seed=abs(seed_store.next()))