Created
December 29, 2018 03:28
-
-
Save hierophantos/0494cbbfcc6de4b1e1b22c42e207086d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import (java.util.concurrent.ThreadLocalRandom)) | |
(defn exp [x n] | |
(loop [acc 1 n n] | |
(if (zero? n) acc | |
(recur (* x acc) (dec n))))) | |
(defn random-bigint [limit] | |
(let [bits (.bitLength limit)] | |
(loop [result (BigInteger. bits (java.util.concurrent.ThreadLocalRandom/current))] | |
(if (< result limit) | |
(bigint result) | |
(recur (BigInteger. bits (java.util.concurrent.ThreadLocalRandom/current))))))) | |
(random-bigint (exp 2N 20)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment