X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Flib%2Fstd%2FRandom.lhs;h=1f19b201bf2dbaf07796b5e4f04c5a487ba7f428;hb=239e9471e104fd88ec93bf42623c3a68a496657a;hp=920d986ca42bf032ab52043e36d4e72b7a00e8b0;hpb=be2c67eb19565e8d0d9ca5a53f526ce49acf1d92;p=ghc-hetmet.git diff --git a/ghc/lib/std/Random.lhs b/ghc/lib/std/Random.lhs index 920d986..1f19b20 100644 --- a/ghc/lib/std/Random.lhs +++ b/ghc/lib/std/Random.lhs @@ -1,5 +1,5 @@ % ------------------------------------------------------------------------------ -% $Id: Random.lhs,v 1.22 2001/02/22 13:17:59 simonpj Exp $ +% $Id: Random.lhs,v 1.25 2001/08/29 10:49:28 simonmar Exp $ % % (c) The University of Glasgow, 1995-2000 % @@ -19,7 +19,7 @@ world.. \begin{code} module Random ( - RandomGen(next, split) + RandomGen(next, split, genRange) , StdGen , mkStdGen , Random ( random, randomR, @@ -37,8 +37,6 @@ import PrelShow ( showSignedInt, showSpace ) import PrelRead ( readDec ) import PrelIOBase ( unsafePerformIO, stToIO ) import PrelArr ( STRef, newSTRef, readSTRef, writeSTRef ) -import PrelReal ( toInt ) -import PrelFloat ( float2Double, double2Float ) import Time ( getClockTime, ClockTime(..) ) #else import PrelPrim ( IORef @@ -55,12 +53,14 @@ import Char ( isSpace, chr, ord ) \begin{code} class RandomGen g where - next :: g -> (Int, g) - split :: g -> (g, g) + next :: g -> (Int, g) + split :: g -> (g, g) + genRange :: g -> (Int,Int) + + -- default mathod + genRange g = (minBound,maxBound) -\end{code} -\begin{code} data StdGen = StdGen Int Int @@ -115,7 +115,7 @@ mkStdGen s createStdGen :: Integer -> StdGen createStdGen s | s < 0 = createStdGen (-s) - | otherwise = StdGen (toInt (s1+1)) (toInt (s2+1)) + | otherwise = StdGen (fromInteger (s1+1)) (fromInteger (s2+1)) where (q, s1) = s `divMod` 2147483562 s2 = q `mod` 2147483398 @@ -176,17 +176,9 @@ instance Random Double where random g = randomR (0::Double,1) g -- hah, so you thought you were saving cycles by using Float? - -#ifdef __HUGS__ instance Random Float where random g = randomIvalDouble (0::Double,1) realToFrac g randomR (a,b) g = randomIvalDouble (realToFrac a, realToFrac b) realToFrac g -#else -instance Random Float where - randomR (a,b) g = randomIvalDouble (float2Double a, float2Double b) double2Float g - random g = randomIvalDouble (0::Double,1) double2Float g -#endif - \end{code}