# Arup Guha
# 8/25/2023
# Simulation to see he probability that two random integers chosen are
# relatively prime...answer is related to the famous Basel Problem

import math
import random


# Produces a random integer, leading digit != 0 with numD digits.
def randNum(numD):

    res = 0

    # Go through each digit.
    for i in range(numD):

        # Set lowest possible digit.
        low = 0
        if i == 0:
            low = 1

        # Generate digit.
        digit = random.randint(low, 9)

        # Update number.
        res = 10*res + digit

    # Ta da!
    return res

# Run a trial where both integers are random integers with numD digits.
def trial(numD):

    # Generate both.
    a = randNum(numD)
    b = randNum(numD)

    # Return 1 iff the two are relatively prime.
    if math.gcd(a,b) == 1:
        return 1
    else:
        return 0

# Set up our tests here.
NUMTRIALS = 100000
NUMDIGITS = 100
success = 0

# Run a bunch of trials.
for i in range(NUMTRIALS):
    success += trial(NUMDIGITS)

# Print result.
prob = success/NUMTRIALS
print("probability relatively prime =", prob)

# Here is the theoretical answer so we can compare!
print("theoretical =",6/math.pi/math.pi)