Random Coprime Pair Generator

Produces N pairs of positive integers (a, b) that are coprime — meaning their greatest common divisor is 1 — sampled by rejection within a min/max range, useful for number theory demonstrations, fraction simplification examples, or generating already-reduced ratio pairs. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-26

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.

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

A batch of coprime pairs

Input

(no input; generated from settings: min 1, max 20, count 3)

Output

(8, 15)
(3, 20)
(1, 1)

Each pair's greatest common divisor is exactly 1.

An impossible range

Input

(no input; generated from settings: min 6, max 6, count 1)

Output

Error: Could not find a coprime pair in this range — widen the min/max range and try again.

The only possible pair is (6, 6), whose GCD is 6, not 1.

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.

References

Frequently Asked Questions