pandemia.random_tools¶
Wrapper around python’s PRNG to ease the process of performing deterministic re-runs
Module Contents¶
Classes¶
Wraps the python random classes as an abstraction layer over them, |
Attributes¶
- pandemia.random_tools.log¶
- pandemia.random_tools.Probability¶
- pandemia.random_tools.T¶
- class pandemia.random_tools.Random(seed=None)¶
Wraps the python random classes as an abstraction layer over them, and offers a number of convenience methods
- gammavariate(alpha: float, beta: float) Probability¶
Sample gamma distributed random variable with pdf given by
x ** (alpha - 1) * math.exp(-x / beta)
- pdf(x) = ————————————–.
math.gamma(alpha) * beta ** alpha
That is, a gamma random variable with shape parameter alpha and scale parameter beta.
- expovariate(lambd: float) Probability¶
Sample exponentially distributed random variable with mean 1 / lambd.
- random_randrange(stop: int) int¶
Random randrange function
- binomial(size: int, prob: float) int¶
Random binomial function
- randrange_interval(start: int, stop: int) int¶
Random randrange function
- random_choice(sequence: Sequence[T]) T¶
Random choice function
- random_choices(population: Sequence[T], weights: Sequence[int], sample_size: int) list[T]¶
Random choices function
- random_sample(population: Sequence[T], k: int) list[T]¶
Select k items from the population given.
- random_shuffle(x: MutableSequence[Any]) None¶
Random shuffle function
- random_float(x: Probability) float¶
Return random number between 0 and x
- multinoulli(problist: Sequence[Probability]) int¶
Sample at random from a list of n options with given probabilities.
Identical to ‘roulette wheel’ random selection.
problist: a list of n items, each of which is a weight.
Returns: The index number of the item chosen
- multinoulli_dict(problist_dict: dict[T, Probability]) T¶
Sample from a key:value dict and return a key according to the weights in the values, i.e.:
{‘a’: 4, ‘b’: 6} has a 60% chance of returning ‘b’ and a 40% chance of returning ‘a’.
- boolean(probability_true: Probability) bool¶
Return true with the probability given.