It is public-key cryptosystem and depends on several facts of number theory, many of which relate to modular arithmetic.
<aside> 💡 Example
Algorithms Unlocked - Thomas H. Cormen (2013)
</aside>
Randomly generate a large odd number and use the primality test (Miller-Rabin preferred) to determine whether it’s prime, stopping once you find a prime number.
<aside> 💡 But we can spend a huge amount of time searching for a prime, right? Actually, no.
The Prime Number Theorem tells us that, as $x$ approaches infinity, the number of prime numbers less than or equal to $x$ approaches $x$ / $\ln{x}$.
</aside>
Relatively prime means that the only common divisor of $e$ and $r$ should be 1 (and so greatest common divisor is 1 too). Any such small integer is fine here.
But how to compute relatively prime integer? We just try to find it by computing d = gcd(e, r) (which must be 1 for relatively prime integer and at this moment we can say that we’ve found it!) for all numbers from 2 until finding it.