randomizer.py

1.1 kB · python · 39 lines

1from typing import List2from mrlypy.core.state import choice, randint, sample, shuffle3from .enums import Edition, Ink, Scheme, Type45# EDITION67def random_edition(editions: List[Edition] = None) -> Edition:8    choices = list(Edition) if editions is None else editions9    return choice(choices)1011# PAINT1213def random_primary(primaries: List[Ink] = None) -> Ink:14    if primaries and len(primaries) == 1:15        return primaries[0]16    choices = [Ink.BLACK, Ink.WHITE]17    if primaries:18        choices = [ink for ink in choices if ink in primaries]19    return choice(choices)2021def random_secondary(count: int = None, primary: Ink = None) -> List[Ink]:22    inks = list(Ink)23    if primary is None:24        inks.remove(Ink.BLACK)25        inks.remove(Ink.WHITE)26    else:27        inks.remove(primary)28    if count is None:29        count = randint(2, 9)30    return sample(inks, count)3132def random_shades(count: int = None, primary: Ink = None) -> List[int]:33    if count == 1:34        return [0] if primary == Ink.BLACK else [1]35    if count is None:36        count = randint(2, 9)37    shades = list(range(count))38    shuffle(shades)39    return shades