Created
May 12, 2011 19:27
-
-
Save clausecker/969253 to your computer and use it in GitHub Desktop.
Leaky program
This file contains 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
{-# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment