Overview
Introduction
This tool generates pairs of positive integers that are coprime — meaning they share no common factor other than 1 — within a range you choose.
It's useful for number theory demonstrations, generating already-fully-reduced fraction examples, or any scenario that specifically calls for relatively prime pairs.
What Is Random Coprime Pair Generator?
A coprime pair generator that uses rejection sampling: it draws random (a, b) pairs from your range and keeps only the ones whose greatest common divisor equals 1.
Coprimality doesn't require either number to be prime itself — for example, 8 and 15 are coprime even though neither is a prime number.
How Random Coprime Pair Generator Works
For each pair, the tool repeatedly draws two random integers from the min/max range and computes their GCD using the Euclidean algorithm.
As soon as a pair with GCD equal to 1 is found, it's accepted; if thousands of attempts fail to find one (because the range structurally can't produce a coprime pair), the tool reports an error instead of looping forever.
When To Use Random Coprime Pair Generator
Use it for number theory teaching examples, generating fraction numerator/denominator pairs that are already in lowest terms, or demonstrating what 'relatively prime' means with concrete values.
For pairs with no coprimality constraint, use Random Number Pair Generator instead.
Often used alongside Random Number Pair Generator, Random Fraction Generator and Random Prime Number Generator.
Features
Advantages
- Guarantees every returned pair is genuinely coprime, not just plausibly so.
- Handles edge cases like a range that can't produce a coprime pair with a clear error rather than an infinite loop.
- Batch generation produces several coprime pairs at once.
Limitations
- Uses rejection sampling, so ranges that are mostly multiples of a small number (like all even numbers) take more attempts internally, though this remains fast for realistic ranges.
- Only supports positive integers — a range including zero or negative numbers is not meaningful for this definition of coprimality here.
Examples
Best Practices & Notes
Best Practices
- Use a reasonably wide range (at least a handful of values) so rejection sampling can quickly find a coprime pair.
- Remember min is floored to at least 1, since coprimality with zero or negative numbers isn't handled by this tool.
Developer Notes
Rejection sampling is capped at 5,000 attempts per pair; for any range with more than one distinct value this succeeds almost immediately, since coprime pairs are common, but the cap prevents a pathological range from hanging the generator.
Random Coprime Pair Generator Use Cases
- Demonstrating the definition of coprime/relatively prime integers with concrete examples
- Generating fraction numerator/denominator pairs guaranteed to already be in lowest terms
- Producing number theory practice problems involving GCD
Common Mistakes
- Setting min and max to the same value expecting any pair to work — only (1, 1) is coprime with itself; any other repeated value fails.
- Assuming coprime implies both numbers are prime — coprimality only requires no shared factor, not primality of either number.
Tips
- Widen the range if you hit the 'could not find a coprime pair' error — a single repeated value rarely works unless it's 1.
- Use the generated pairs directly as already-reduced fraction numerator/denominator examples.