1

ive created a function that finds the gcd of 2 numbers for me, but when using this in a new function, to find the product of 2 random prime numbers, my function doesnt seem to work; it gives me non-prime numbers.

def png():
    b=0
    c=0
    while gcd(b,c) != 1:
        b= random.randint(1,1*10**20)
        c= random.randint(1,1*10**20)
    if gcd(b,c) == 1:
        return b*c

can someone help me solve this please

Sara
  • 33
  • 4

1 Answers1

0

to find the product of 2 random prime numbers

Your code finds coprime numbers, not prime numbers. https://en.wikipedia.org/wiki/Coprime_integers For instance, GCD of 9 and 14 is 1, but neither of them is prime.

If you want to find prime numbers, I suggest using sieve of Eratosthenes

WojciechR
  • 323
  • 1
  • 6