API Reference

exhaust.space(fn, verbose=False)

Return an iterable that generates values from fn fully exhausting the state space.

During iteration, the function fn is called repeatedly with a State instance as only argument.

Parameters
  • fn (Callable[[State], ~T]) – The function to generate values from.

  • verbose (bool) – If True, print the state of the generator.

Return type

Iterable[~T]

class exhaust.State(verbose=False)

An instance of this class is passed as argument to the function passed to space().

choice(seq)

Return an element from the non-empty sequence seq.

This is the equivalent of random.choice().

Parameters

seq (Iterable[~T]) – The sequence from which to choose from.

Raises

IndexError – if seq is empty.

Return type

~T

choices(population, *, k=1)

Return a k sized list of elements chosen from the population with replacement.

This is the equivalent of random.choices(), minus the weights and cum_weights arguments.

Parameters
  • population (Iterable[~T]) – The population from which to choose from.

  • k (int) – The number of elements to choose.

Raises

IndexError – if population is empty.

Return type

List[~T]

maybe()

Return True or False. Alias for choice([True, False]).

Return type

bool

randint(a, b)

Return an integer N such that a <= N <= b. Alias for randrange(a, b+1).

This is the equivalent of random.randint().

Parameters
  • a (int) – The start of the range.

  • b (int) – The end of the range (inclusive).

Raises

ValueError – if the range is empty.

Return type

int

randrange(stop: int) int
randrange(start: int, stop: int, step: Optional[int] = None) int

Return an element from range(start, stop, step).

This is the equivalent of random.randrange().

Parameters
  • start – The start of the range.

  • stop – The end of the range (exclusive).

  • step – The step size.

Raises

ValueError – if the range is empty.

Return type

int

sample(population, k, *, counts=None)

Return a k sized list of unique elements chosen from the population.

This is the equivalent of random.sample().

Parameters
  • population (Sequence[~T]) – The population from which to choose from.

  • k (int) – The number of elements to choose.

  • counts (Optional[Iterable[int], None]) – The number of times each element is repeated.

Raises

ValueError – if k is larger than the population size.

Return type

List[~T]