diff --git a/procsim/core/main.py b/procsim/core/main.py index 8c49e5d..fa3958f 100755 --- a/procsim/core/main.py +++ b/procsim/core/main.py @@ -8,6 +8,7 @@ import importlib import json import os +import random import signal import sys from typing import List, Optional, Tuple @@ -328,6 +329,10 @@ def parse_command_line(): def main(): task_filename, job_filename, config_filename, scenario_name, log_level, no_match_outputs = parse_command_line() logger = Logger('', '', '', Logger.LEVELS, []) # Create temporary logger + + # init random generator with fixed seed to ensure reproducibility. + random.seed(0) + try: # Program terminate/interrupt, will raise an exception which in turn will # result in a log message. diff --git a/procsim/flex/product_generator.py b/procsim/flex/product_generator.py index f32b993..1dc3575 100644 --- a/procsim/flex/product_generator.py +++ b/procsim/flex/product_generator.py @@ -4,6 +4,7 @@ import bisect import datetime import os +import random import re import shutil from typing import Dict, Iterable, List, Optional, Tuple @@ -202,12 +203,15 @@ def _generate_bin_file(self, file_path: str, size_mb: Optional[int]) -> None: input_file.close() # otherwise look at 'size' (default 0) and write random data + # use randbytes if available (Python >= 3.9), otherwise fall back to os.urandom else: size = size_mb * 2**20 if size_mb is not None else 0 - while size > 0: amount = min(size, CHUNK_SIZE) - output_file.write(os.urandom(max(amount, 0))) + if hasattr(random, 'randbytes'): + output_file.write(random.randbytes(amount)) + else: + output_file.write(os.urandom(amount)) size -= amount output_file.close()