diff options
| author | pepperpepperpepper <pepper@scannerjammer.com> | 2015-11-29 17:43:44 -0800 |
|---|---|---|
| committer | pepperpepperpepper <pepper@scannerjammer.com> | 2015-11-29 17:43:44 -0800 |
| commit | 9a7bf3bffb2a8459e66b988aaff53611723b5ab4 (patch) | |
| tree | cc4ef0de15e22f5c6e5f8d2ecf16db0486d7a8ff /ricky/unused/weight.py | |
| parent | 10a619b2c7227b2ad214fbb985141b884fbe87fb (diff) | |
required=0, -e commit message for your changes. Lines starting
Diffstat (limited to 'ricky/unused/weight.py')
| -rw-r--r-- | ricky/unused/weight.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/ricky/unused/weight.py b/ricky/unused/weight.py new file mode 100644 index 0000000..4bd4af4 --- /dev/null +++ b/ricky/unused/weight.py @@ -0,0 +1,57 @@ + weights_total = sum( + map(lambda x: x["weight"], self.probabilities()) + ) + (255 * 255 * 255) + choice = random.randint(0, weights_total) + position = 0 + for elem in self.probabilities(): + position += elem["weight"] + if position >= choice: + self.value = elem["value"] + return + + weights_total = sum( + map(lambda x: x["weight"], self.probabilities()) + )# + self.range_max - self.range_min + if weights_total < 100: + weights_total = 100; + choice = random.randint(0, weights_total) + import sys + sys.stderr.write("choosing %s: random_int: %s, probabilities: %s\n" % ( + self.name, + choice, + self.probabilities())) + position = 0 + for elem in self.probabilities(): + position += elem["weight"] + if position >= choice: + self.value = elem["value"] + return + + + weights_total = sum(map(lambda x: x["weight"], self.probabilities())) + choice = random.randint(0, weights_total) + position = 0 + for elem in self.probabilities(): + position += elem["weight"] + if position >= choice: + self.value = elem["value"] + break + def _choose_heaviest(self): + heaviest_idx = 0 + heaviest_weight = 0 + idx = 0 + if (len(self.options())): + for elem in self.options(): + if elem["weight"] > heaviest_weight: + heaviest_weight = elem["weight"] + heaviest_idx = idx + idx += 1 + return self.options()[heaviest_idx]["value"] + else: + self.randomize() + + def heaviest(self): + self.value = self._choose_heaviest() + + """default value is the probability with the heaviest weight""" + self.default(self._choose_heaviest()) |
