fork download
  1. import qualified Data.IntMap as I
  2. import Control.Monad
  3. import Data.List
  4. import Data.Maybe
  5. import System.Random
  6.  
  7. main :: IO ()
  8. main = do
  9. rd <- replicateM 100000 $ rollIkasamaDice (take 6 $ cycle [1,2])
  10. rd1 <- replicateM 100000 $ rollIkasamaDice (map sqrt [1..4])
  11. let im = foldr (I.update ((Just $!) . succ)) im0 rd
  12. im0 = I.fromList $ zip [1..6] [0,0..]
  13. print im
  14.  
  15. rollIkasamaDice :: [Double] -> IO Int
  16. rollIkasamaDice dist = do
  17. d <- getStdRandom (randomR (0, 1)) :: IO Double
  18. let thr = scanl1 (+) $ map . flip (/) =<< sum $ dist
  19. a = zip thr [1..] :: [(Double, Int)]
  20.  
  21. return $ snd $ fromJust $ find ((d <=) . fst) a
  22.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.hs:5:8:
    Could not find module `System.Random'
    Use -v to see a list of the files searched for.
stdout
Standard output is empty