diff options
| author | pepperpepperpepper <pepper@scannerjammer.com> | 2015-12-07 14:40:04 -0800 |
|---|---|---|
| committer | pepperpepperpepper <pepper@scannerjammer.com> | 2015-12-07 14:40:04 -0800 |
| commit | e1a642e41e7e6d08303573fb20f265b4ac326372 (patch) | |
| tree | 9d2a33ae7e9816dfd0a0dc2e819e78ea45539c1b /ricky/param/__init__.py | |
| parent | f38100a74f0d88cafeac8fb4c8fb99241007da08 (diff) | |
added support for probabilities
Diffstat (limited to 'ricky/param/__init__.py')
| -rw-r--r-- | ricky/param/__init__.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/ricky/param/__init__.py b/ricky/param/__init__.py index cbacf6f..4ec8204 100644 --- a/ricky/param/__init__.py +++ b/ricky/param/__init__.py @@ -1,4 +1,5 @@ import pprint +import random class Param(object): @@ -53,7 +54,21 @@ class Param(object): default = property(default_get, default_set) - def randomize(self): + def _choose_from_probabilities(self, probabilities): + """ + if using weights, considers all weights as a percentage of + 100 + """ + choice = random.randint(0, 100) + position = 0 + for elem in probabilities: + position += elem["weight"] + if position >= choice: + self.value = elem["value"] + return True + return True + + def randomize(self, probabilities=None): pass def from_normalized(self, value): |
