nextapps-be/unique-codes

Question

gravataLonga opened this issue · 3 comments

I've a question, two primes number that you need to obfuscate sequential number, must be coprimes?

In this link:
https://web.archive.org/web/20170730030023/http://blog.mischel.com/2017/06/20/how-to-generate-random-looking-keys/

const long m = 101;         // Number of keys + 1
const long x = 387420489;   // must be coprime to m

Indeed, m and x must be coprimes. You could use 2 non-prime numbers that are coprimes, but it's easier to just use 2 prime numbers. 2 prime numbers are always coprimes :)

Sorry I'm not expertise on math. So, are you telling me that two primes number it's always a coprimes?

Yes, coprimes are numbers that only have 1 as a common divisor. (For example, numbers 14 and 25 are coprimes, while 14 and 21 are not). A prime number is already a number that only has 1 as a divisor, so that means 2 prime numbers are always coprime to each other.