The problem is (long (rand m))
, because the random value you choose is often a lot more than it can fit into a long one. You want to make bigint not for long. Here is one way:
(bigint (bigdec (rand 38941629971148227236N)))
Note that choosing random numbers in this way really creates a double that will convert to bigdec, which will convert to bigit. Thus, the range of possible random values ββis limited. Using a double as a base random number means that all possible bandages will not be created. If you want a true random selection in bigint format, take a look at this answer ... but if you don't care, if you get a lot of sense in the right one, this might work for you:
(defn find-e [m] (loop [e (bigint (bigdec (rand m)))] (if (= 1 (gcd em)) e (recur (bigint (bigdec (rand m)))))))
source share