Remove backported rand func (Superseded)
This commit is contained in:
parent
7533b82331
commit
43d18f0de1
@ -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))
|
||||
|
@ -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))]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user