[commit: random] master: Minor: Added a bit of testing related code corresponding to ticket 5278. (ca16c62)
Ian Lynagh
igloo at earth.li
Fri Jul 8 18:47:23 CEST 2011
Repository : ssh://darcs.haskell.org//srv/darcs/packages/random
On branch : master
http://hackage.haskell.org/trac/ghc/changeset/ca16c628a340107aba04d75757910cecac90c4f3
>---------------------------------------------------------------
commit ca16c628a340107aba04d75757910cecac90c4f3
Author: Ryan Newton <rrnewton at gmail.com>
Date: Sun Jun 26 22:52:08 2011 -0400
Minor: Added a bit of testing related code corresponding to ticket 5278.
>---------------------------------------------------------------
Benchmark/SimpleRNGBench.hs | 20 ++++++++++++++++++--
System/Random.hs | 1 +
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/Benchmark/SimpleRNGBench.hs b/Benchmark/SimpleRNGBench.hs
index 2d1bd72..4b4d42d 100644
--- a/Benchmark/SimpleRNGBench.hs
+++ b/Benchmark/SimpleRNGBench.hs
@@ -21,7 +21,7 @@ import Data.IORef
import Data.Word
import Data.List hiding (last,sum)
import Data.Int
-import Data.List.Split
+import Data.List.Split hiding (split)
import Text.Printf
import Foreign.Ptr
@@ -80,7 +80,6 @@ measureFreq = do
return$ fromIntegral (t2 - t1)
----------------------------------------------------------------------------------------------------
--- Drivers to get random numbers repeatedly.
-- Test overheads without actually generating any random numbers:
data NoopRNG = NoopRNG
@@ -92,6 +91,23 @@ instance SplittableGen NoopRNG where
#endif
split g = (g,g)
+-- An RNG generating only 0 or 1:
+data BinRNG = BinRNG StdGen
+instance RandomGen BinRNG where
+ next (BinRNG g) = (x `mod` 2, BinRNG g')
+ where (x,g') = next g
+#if 1
+ genRange _ = (0,1)
+instance SplittableGen BinRNG where
+#endif
+ split (BinRNG g) = (BinRNG g1, BinRNG g2)
+ where (g1,g2) = split g
+
+mkBinRNG = BinRNG . mkStdGen
+
+----------------------------------------------------------------------------------------------------
+-- Drivers to get random numbers repeatedly.
+
type Kern = Int -> Ptr Int -> IO ()
-- [2011.01.28] Changing this to take "count" and "accumulator ptr" as arguments:
diff --git a/System/Random.hs b/System/Random.hs
index b36cb28..693566f 100644
--- a/System/Random.hs
+++ b/System/Random.hs
@@ -418,6 +418,7 @@ randomIvalInteger (l,h) rng
randomFrac :: (RandomGen g, Fractional a) => g -> (a, g)
randomFrac = randomIvalDouble (0::Double,1) realToFrac
+-- BUG: Ticket #5133 - this was found to generate the hi bound for Floats:
randomIvalFrac :: (RandomGen g, Real a, Fractional b) => (a,a) -> g -> (b, g)
randomIvalFrac (a,b) = randomIvalDouble (realToFrac a, realToFrac b) realToFrac
More information about the Cvs-libraries
mailing list