From 43d18f0de199786815de4ecb2893f2dc5a466af4 Mon Sep 17 00:00:00 2001 From: LoafyLemon Date: Tue, 3 Jan 2023 20:04:11 +0000 Subject: [PATCH] Remove backported rand func (Superseded) --- game/scripts/inventory/game.rpy | 2 +- game/scripts/utility/common_functions.rpy | 39 ----------------------- 2 files changed, 1 insertion(+), 40 deletions(-) diff --git a/game/scripts/inventory/game.rpy b/game/scripts/inventory/game.rpy index 1e36c956..9d7a6463 100644 --- a/game/scripts/inventory/game.rpy +++ b/game/scripts/inventory/game.rpy @@ -59,7 +59,7 @@ init python: @weather.setter def weather(self, value): if value == "random": - value = random_choices(self.weather_types, weights=self.weather_weights)[0] + value = renpy.python.random.choices(self.weather_types, weights=self.weather_weights)[0] if not value in self.weather_types: raise ValueError("Unsupported weather type: '{}'".format(value)) diff --git a/game/scripts/utility/common_functions.rpy b/game/scripts/utility/common_functions.rpy index f5a82f0b..43900fdf 100644 --- a/game/scripts/utility/common_functions.rpy +++ b/game/scripts/utility/common_functions.rpy @@ -145,45 +145,6 @@ init -1 python: """Mutates the original list.""" l[val1], l[val2] = l[val2], l[val1] - def random_choices(population, weights=None, cum_weights=None, k=1): - """Backported from python 3.6 - - Return a k sized list of population elements chosen with replacement. - If the relative weights or cumulative weights are not specified, - the selections are made with equal probability. - """ - - def accumulate(iterable, func=_add, initial=None): - it = iter(iterable) - total = initial - if initial is None: - try: - total = next(it) - except StopIteration: - return - yield total - for element in it: - total = func(total, element) - yield total - - random = renpy.random.random - if cum_weights is None: - if weights is None: - _int = int - total = len(population) - return [population[_int(random() * total)] for i in range(k)] - cum_weights = list(accumulate(weights)) - elif weights is not None: - raise TypeError('Cannot specify both weights and cumulative weights') - - if len(cum_weights) != len(population): - raise ValueError('The number of weights does not match the population') - - #bisect = _bisect.bisect - total = cum_weights[-1] - hi = len(cum_weights) - 1 - return [population[bisect(cum_weights, random() * total, 0, hi)] for i in range(k)] - def natsort_key(s, pattern=re.compile("([0-9]+)")): return [int(t) if t.isdigit() else t.lower() for t in pattern.split(str(s))]