Skip to content

generators.utils.choices

Data - Generators - Choices¤

Choices ¤

Generating data by choosing from some given values.

elements = [0,1]
c = Choices(elements=elements)
next(c)

:param elements: the elements to choose from :param seed: seed of the RNG for reproducibility

Source code in eerily/generators/utils/choices.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class Choices:
    """Generating data by choosing from some given values.

    ```python
    elements = [0,1]
    c = Choices(elements=elements)
    next(c)
    ```

    :param elements: the elements to choose from
    :param seed: seed of the RNG for reproducibility
    """

    def __init__(
        self,
        elements: Sequence[Any],
        seed: Optional[float] = None,
    ):
        self.elements = elements
        self.indices = range(len(elements))

        self.rng = np.random.default_rng(seed=seed)

    def __next__(self) -> Any:
        idx = self.rng.choice(self.indices)
        return self.elements[idx]