refactor: Replace Random import with random module and update type hints

This commit is contained in:
Andreas Koepf 2025-01-23 12:01:20 +01:00 committed by Andreas Koepf (aider)
parent 654bed3146
commit 358829cc60

View file

@ -1,5 +1,5 @@
from dataclasses import dataclass
from random import Random
import random
from typing import Optional
@ -33,7 +33,7 @@ class ChainSum:
self.config = config
self.config.validate()
# Generate base seed if none provided
self.seed = config.seed if config.seed is not None else Random().randint(0, 2**32)
self.seed = config.seed if config.seed is not None else random.randint(0, 2**32)
def __len__(self) -> int:
return self.config.size
@ -50,8 +50,8 @@ class ChainSum:
- answer: str, the ground truth result
- metadata: dict with generation parameters
"""
# Create deterministic RNG directly from base seed and idx
item_rng = Random(self.seed + idx)
# Create deterministic RNG from base seed and idx
item_rng = random.Random(self.seed + idx)
num_terms = item_rng.randint(self.config.min_terms, self.config.max_terms)
num_digits = item_rng.randint(self.config.min_digits, self.config.max_digits)
@ -68,7 +68,7 @@ class ChainSum:
}
}
def _generate_task(self, rng: Random, num_terms: int, num_digits: int) -> tuple[str, int]:
def _generate_task(self, rng: random.Random, num_terms: int, num_digits: int) -> tuple[str, int]:
"""Generate a chain sum task
Args: