fault_injection_async25_paper/test-circuit/randomizer.py

31 lines
No EOL
1,015 B
Python

import re
import random
def replace_after_pattern(text):
# Define a function to generate a random number between 950 and 1050
def random_replacement(match):
return f"[after={random.randint(95, 105)}]"
# Use re.sub to find all instances of '[after=1000]' and replace with random number
result = re.sub(r'\[after=1000\]', random_replacement, text)
return result
def process_file(input_filename, output_filename):
# Read content from the input file
with open(input_filename, 'r') as input_file:
text = input_file.read()
# Replace the patterns in the text
updated_text = replace_after_pattern(text)
# Save the updated text to the output file
with open(output_filename, 'w') as output_file:
output_file.write(updated_text)
# Example usage
input_file = 'prs/umul4x4_DIMS_delay.act' # Replace with your input file name
output_file = 'prs/umul4x4_DIMS_rand.act' # Replace with your desired output file name
process_file(input_file, output_file)