def sample(self):
return random.paretovariate(self.alpha)
python类paretovariate()的实例源码
def sample(self):
return random.paretovariate(self.alpha)
def _execute(self, sources, alignment_stream, interval):
if alignment_stream is None:
raise ToolExecutionError("Alignment stream expected")
for ti, _ in alignment_stream.window(interval, force_calculation=True):
yield StreamInstance(ti, random.paretovariate(alpha=self.alpha))
def _resource_pr(self, resource, x, y, distance, deposit):
seed("{}.{}".format(x, y))
if resource == 'clay':
v = paretovariate(2) / (distance + 1)
return v if v > .2 else 0
if resource == 'elevation':
return paretovariate(4) / (distance + 1)
if resource == 'ore':
dx, dy, dr = deposit
angle = math.atan2(dy - y, dx - x) % math.pi
diff = .5 / (angle - dr + .5)
v = paretovariate(2) / (distance + 1) * diff
return v if v > .4 else 0