Created
October 2, 2013 03:01
-
-
Save trevordixon/6788540 to your computer and use it in GitHub Desktop.
Find a Large Random Prime Number in Haskell
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 System.Random | |
import Math.NumberTheory.Primes.Testing | |
rndPrime :: Int -> IO Integer | |
rndPrime bits = do | |
x <- fmap (.|. 1) $ randomRIO (2^(bits - 1), 2^bits - 1) | |
if isPrime x then return x else rndPrime bits |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment