public
Last active

Leaky program

  • Download Gist
leaky.hs
Haskell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
{-# Language TupleSections #-}
 
import System.Random
import Data.Map (fromListWith,Map)
import Control.Arrow
 
randomStream 0 g = ([],g)
randomStream n g = (a:as,g'') where
(a,g') = randomR (0,100) g
(as,g'') = randomStream (n-1) g'
 
makeStats :: Int -> StdGen -> (Map Int Int, StdGen)
makeStats n g = first (fromListWith (+) . map (,1)) $ randomStream n g
 
main = getStdGen >>= print . makeStats 10000000

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.