Basic-benchmark-experiment/Python/code_unoptimised.py

18 lines
397 B
Python
Raw Permalink Normal View History

2024-03-11 12:43:52 +02:00
from random import randint
total_attempts = 15_000_000
successful_attempts = 0
for i in range(0, total_attempts):
a = randint(0, 256)
b = randint(0, 256)
c = randint(0, 256)
if a + b + c > 300:
successful_attempts += 1
print(f"Iterations: {total_attempts}")
print(f"Valid sums: {successful_attempts}")
print(f"Probability: {successful_attempts / total_attempts}")