packages feed

RandomDotOrg (empty) → 0.1

raw patch · 4 files changed

+57/−0 lines, 4 filesdep +HTTP-Simpledep +basedep +networksetup-changed

Dependencies added: HTTP-Simple, base, network

Files

+ LICENSE view
@@ -0,0 +1,1 @@+This work is in the public domain. Use it for whatever you wish.
+ RandomDotOrg.cabal view
@@ -0,0 +1,16 @@+name:                RandomDotOrg+version:             0.1+build-type:          Simple+Cabal-Version:       >= 1.2+synopsis:            Interface to random numbers on random.org+description:         Using this package you can generate random numbers+		     (based on the atmosphere, not a PRNG) via the random.org website+category:            Other+license:             PublicDomain+license-file:        LICENSE+author:              Austin Seipp+maintainer:          mad.one@gmail.com++library+  build-depends:       base, HTTP-Simple >= 0.1, network+  exposed-modules:     RandomDotOrg
+ RandomDotOrg.hs view
@@ -0,0 +1,37 @@+module RandomDotOrg (getRandomNumbers) where+import Data.Either+import Network.URI+import Network.HTTP.Simple++uri num min max +    = concat [ "http://random.org/integers/?num="+             , show num+             , "&min="+             , show min+             , "&max="+             , show max+             , "&col=1&base=10&format=plain&rnd=new" ]++-- | Used to get a list of random numbers from http://random.org.+-- Note: the minimum must be greater than the maximum. The maximum+-- amount of numbers you can retrieve is 10,000, and the numbers +-- themselves are limited to a range of +/- 1,000,000,000 (inclusive)+getRandomNumbers :: Int -- ^ Number of integers to get+                 -> Int -- ^ Minimum number+                 -> Int -- ^ Maximum number+                 -> IO (Either String [Int]) -- ^ Returns either an error string or the list of integers+getRandomNumbers num min max+    | max <= min           = return $ Left "err: minimum must be greater than maximum"+    | num > 10000          = return $ Left "err: can't retrieve more than 10,000 numbers"+    | abs min > 1000000000 = return $ Left "err: min can't be more/less than 1,000,000,000"+    | abs max > 1000000000 = return $ Left "err: max can't be more/less than 1,000,000,000"+    | otherwise            = do+        let uri' = parseURI (uri num min max)+        case uri' of+          Nothing -> return $ Left "err: Network.URI.parseURI returned Nothing"+          Just u  -> getResult u+ where getResult u = do+           s <- httpGet u+           case s of+             Nothing -> return $ Left "err: Network.HTTP.Simple.httpGet returned Nothing"+             Just s'  -> return $ Right (map read (lines s'))
+ Setup.lhs view
@@ -0,0 +1,3 @@+#!/usr/bin/env runhaskell+> import Distribution.Simple+> main = defaultMain