Skip to content

Instantly share code, notes, and snippets.

@trevordixon
Created October 2, 2013 03:01
Show Gist options
  • Save trevordixon/6788540 to your computer and use it in GitHub Desktop.
Save trevordixon/6788540 to your computer and use it in GitHub Desktop.
Find a Large Random Prime Number in Haskell
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