I'm sorry if this is an obvious question, but I'm a newbie and googling didn't help me much.
Is there a way in Mathematica to generate a number q
coprime with p
without resorting to do it "by hand" by iterating over a list of random numbers and using CoprimeQ
?
I see how the likelihood of hitting a coprime soon is pretty good, but I wonder if there is a cleaner, or, if you want, more Mathematica-like way to do it.
Thank you very much.
(While[ ! CoprimeQ[n , i = RandomInteger[n]]]; i)
is much faster than the "more elegant" answers.. $\endgroup$ – george2079 Apr 15 '15 at 15:08