Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import time
- import sys
- def generate_normal_dist_values(size, min_val, max_val):
- # Generates an array of 'size' normally distributed values between 'min_val' and 'max_val'.
- mean = (max_val + min_val) / 2
- std_dev = (max_val - min_val) / 4 # Approx. 99.7% of values within min and max
- values = np.random.normal(loc=mean, scale=std_dev, size=size)
- values = np.clip(values, min_val, max_val)
- return values
- def display_progress_bar(iteration, total, length=50):
- # Displays a progress bar in the command line.
- percent = "{0:.0f}".format(100 * (iteration / float(total)))
- filled_length = int(length * iteration // total)
- bar = '█' * filled_length + '░' * (length - filled_length)
- sys.stdout.write(f'\r|{bar}| {percent}% Complete')
- sys.stdout.flush()
- def main():
- # Main function to run the progress bar.
- total_iterations = 100
- min_val = 0.01
- max_val = 5
- sleep_multiplier = 0.15 # 150ms
- # Generate 101 normally distributed values
- sleep_times = generate_normal_dist_values(total_iterations + 1, min_val, max_val)
- for i in range(total_iterations + 1):
- display_progress_bar(i, total_iterations)
- time.sleep(sleep_times[i] * sleep_multiplier)
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement