Permalink
Browse files

Minor: Added a bit of testing related code corresponding to ticket 5278.

  • Loading branch information...
1 parent 6280211 commit ca16c628a340107aba04d75757910cecac90c4f3 @rrnewton rrnewton committed Jun 27, 2011
Showing with 19 additions and 2 deletions.
  1. +18 −2 Benchmark/SimpleRNGBench.hs
  2. +1 −0 System/Random.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:
View
@@ -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

0 comments on commit ca16c62

Please sign in to comment.