File: TestRandomRs.hs

package info (click to toggle)
haskell-random 1.2.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 296 kB
  • sloc: haskell: 2,696; makefile: 3
file content (23 lines) | stat: -rw-r--r-- 658 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
-- Test for ticket #4218 (TestRandomRs):
-- https://ghc.haskell.org/trac/ghc/ticket/4218
--
-- Fixed together with ticket #8704
-- https://ghc.haskell.org/trac/ghc/ticket/8704
-- Commit 4695ffa366f659940369f05e419a4f2249c3a776
--
-- Used to fail with:
--
-- $ cabal test TestRandomRs --test-options="+RTS -M1M -RTS"
-- TestRandomRs: Heap exhausted;

module TestRandomRs where

import Control.Monad (liftM)
import System.Random (randomRs, getStdGen)

-- Return the five-thousandth random number:
-- Should run in constant space (< 1Mb heap).
main :: IO ()
main = do
    n <- (last . take 5000 . randomRs (0, 1000000)) `liftM` getStdGen
    print (n::Integer)