Skip to content

Commit

Permalink
Python 3.12: Fix TypeError on random.randint() with float values
Browse files Browse the repository at this point in the history
TypeError: 'float' object cannot be interpreted as an integer.
  • Loading branch information
amotl committed May 18, 2024
1 parent b951a4b commit d75922f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion tsperf/util/float_simulator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ def _decide_factor(self):
change_direction = 1
chance = (50 * self.standard_deviation) - distance

return continue_direction if random.randint(0, (100 * self.standard_deviation)) < chance else change_direction
return (
continue_direction if random.randint(0, int(100 * self.standard_deviation)) < chance else change_direction
)

def _new_error_value(self):
self.error_count += 1
Expand Down
2 changes: 1 addition & 1 deletion tsperf/write/model/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ def __init__(self, schema):
self.true_ratio = self.schema["true_ratio"]["value"]

def calculate_next_value(self) -> bool:
return random.randint(0, (1 / self.true_ratio)) < 1 # noqa:S311
return random.randint(0, int(1 / self.true_ratio)) < 1 # noqa:S311

0 comments on commit d75922f

Please sign in to comment.