Coverage for moptipy / operators / bitstrings / op0_random.py: 100%
8 statements
« prev ^ index » next coverage.py v7.12.0, created at 2025-11-24 08:49 +0000
« prev ^ index » next coverage.py v7.12.0, created at 2025-11-24 08:49 +0000
1"""A nullary operator filling a bit string with random values."""
4import numpy as np
5from numpy.random import Generator
7from moptipy.api.operators import Op0
10class Op0Random(Op0):
11 """Fill a bit string with random values."""
13 def op0(self, random: Generator, dest: np.ndarray) -> None:
14 """
15 Fill the string `dest` with random values.
17 :param random: the random number generator
18 :param dest: the bit string to fill. Afterwards, its contents will
19 be random.
20 """
21 np.copyto(dest, random.integers(0, 2, dest.shape, dest.dtype))
23 def __str__(self) -> str:
24 """
25 Get the name of this operator.
27 :return: "randomize"
28 """
29 return "randomize"