From d75922f2e7f0e990689743fd58bc48563babac67 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Sat, 18 May 2024 23:14:48 +0200 Subject: [PATCH] Python 3.12: Fix TypeError on random.randint() with `float` values TypeError: 'float' object cannot be interpreted as an integer. --- tsperf/util/float_simulator/__init__.py | 4 +++- tsperf/write/model/sensor.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tsperf/util/float_simulator/__init__.py b/tsperf/util/float_simulator/__init__.py index 034e0d5..f3ffd2a 100644 --- a/tsperf/util/float_simulator/__init__.py +++ b/tsperf/util/float_simulator/__init__.py @@ -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 diff --git a/tsperf/write/model/sensor.py b/tsperf/write/model/sensor.py index f41f3f6..70a4a5d 100644 --- a/tsperf/write/model/sensor.py +++ b/tsperf/write/model/sensor.py @@ -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