Skip to content

Commit

Permalink
add random-high and random-low to Range Options
Browse files Browse the repository at this point in the history
  • Loading branch information
Berserker66 committed Jun 8, 2021
1 parent adda0ef commit 471b217
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Options.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,14 @@ def __init__(self, value: typing.Union[str, int]):

@classmethod
def from_text(cls, text: str) -> Range:
if text.lower() == "random":
return cls(random.randint(cls.range_start, cls.range_end))
text = text.lower()
if text.startswith("random"):
if text == "random-low":
return cls(int(round(random.triangular(cls.range_start, cls.range_end, cls.range_start), 0)))
elif text == "random-high":
return cls(int(round(random.triangular(cls.range_start, cls.range_end, cls.range_end), 0)))
else:
return cls(random.randint(cls.range_start, cls.range_end))
number = int(text)
if number < cls.range_start:
raise Exception(f"{number} is lower than minimum {cls.range_start} for option {cls.__name__}")
Expand Down

0 comments on commit 471b217

Please sign in to comment.