mersenne-random-pure64 0.2.0.3 → 0.2.0.4
raw patch · 6 files changed
+13/−256 lines, 6 filesdep ~basenew-uploader
Dependency ranges changed: base
Files
- LICENSE.mt19937-64 +0/−54
- System/Random/Mersenne/Pure64/MTBlock.hs +4/−0
- TODO +0/−17
- mersenne-random-pure64.cabal +9/−5
- tests/Unit.hs +0/−165
- tests/copy.hs +0/−15
− LICENSE.mt19937-64
@@ -1,54 +0,0 @@-/* - A C-program for MT19937-64 (2004/9/29 version).- Coded by Takuji Nishimura and Makoto Matsumoto.-- This is a 64-bit version of Mersenne Twister pseudorandom number- generator.-- Before using, initialize the state by using init_genrand64(seed) - or init_by_array64(init_key, key_length).-- Copyright (C) 2004, Makoto Matsumoto and Takuji Nishimura,- All rights reserved. -- Redistribution and use in source and binary forms, with or without- modification, are permitted provided that the following conditions- are met:-- 1. Redistributions of source code must retain the above copyright- notice, this list of conditions and the following disclaimer.-- 2. Redistributions in binary form must reproduce the above copyright- notice, this list of conditions and the following disclaimer in the- documentation and/or other materials provided with the distribution.-- 3. The names of its contributors may not be used to endorse or promote - products derived from this software without specific prior written - permission.-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.-- References:- T. Nishimura, ``Tables of 64-bit Mersenne Twisters''- ACM Transactions on Modeling and - Computer Simulation 10. (2000) 348--357.- M. Matsumoto and T. Nishimura,- ``Mersenne Twister: a 623-dimensionally equidistributed- uniform pseudorandom number generator''- ACM Transactions on Modeling and - Computer Simulation 8. (Jan. 1998) 3--30.-- Any feedback is very welcome.- http://www.math.hiroshima-u.ac.jp/~m-mat/MT/emt.html- email: m-mat @ math.sci.hiroshima-u.ac.jp (remove spaces)-*/
System/Random/Mersenne/Pure64/MTBlock.hs view
@@ -30,7 +30,11 @@ ) where import GHC.Exts+#if __GLASGOW_HASKELL__ >= 706+import GHC.IO+#else import GHC.IOBase+#endif import GHC.Word import System.Random.Mersenne.Pure64.Base
− TODO
@@ -1,17 +0,0 @@--fvia-C seems to break things!- The problem is that the prototypes of the imported functions don't get- propagated properly, leading to warnings like this:-- /tmp/ghc7602_0/ghc7602_0.hc:718:0:- warning: implicit declaration of function 'mix_bits'-- This is actually an error on 32 bit machines - the default return type- int is not large enough to hold the 64 bit result.-- This is fixed in ghc 6.9; the compiler emits its own prototypes.-Check sequences are repeatable-Investigate slow conversion to Double (x86 at least)- looking at the core, the conversion goes through toInteger and encodeFloat.- That's a pity, because the FPU has an instruction for this purpose.-profile/benchmark-tests driver
mersenne-random-pure64.cabal view
@@ -1,5 +1,5 @@ name: mersenne-random-pure64-version: 0.2.0.3+version: 0.2.0.4 homepage: http://code.haskell.org/~dons/code/mersenne-random-pure64/ synopsis: Generate high quality pseudorandom numbers purely using a Mersenne Twister description:@@ -21,12 +21,16 @@ category: Math, System license: BSD3 license-file: LICENSE-copyright: (c) 2008. Don Stewart <dons@galois.com>+copyright: (c) 2008. Don Stewart <dons00@gmail.com> author: Don Stewart-maintainer: Don Stewart <dons@galois.com>-cabal-version: >= 1.2.0+maintainer: Don Stewart <dons00@gmail.com>+cabal-version: >= 1.6.0 build-type: Simple-tested-with: GHC == 6.8.3+tested-with: GHC == 7.6.2, GHC == 7.7++source-repository head+ type: git+ location: git://github.com/bgamari/mersenne-random-pure64 flag small_base description: Build with new smaller base library
− tests/Unit.hs
@@ -1,165 +0,0 @@-{-# LANGUAGE BangPatterns #-}--- A basic correctness and performance test for mersenne-random-pure64.------ Copyright (c) 2008, Don Stewart <dons@galois.com>--import Control.Exception-import Control.Monad-import Data.Int-import Data.Typeable-import Data.Word-import System.CPUTime-import System.Environment-import System.IO-import Text.Printf-import qualified System.Random as Old-import qualified System.Random.Mersenne as Unsafe--import System.Random.Mersenne.Pure64-import System.Random.Mersenne.Pure64.Base-import Control.Concurrent-import Control.Concurrent.MVar--time :: IO t -> IO t-time a = do- start <- getCPUTime- v <- a- end <- getCPUTime- let diff = (fromIntegral (end - start)) / (10^12)- printf "Computation time: %0.3f sec\n" (diff :: Double)- return v--seed = 7--main = do-- c_init_genrand64_unsafe seed- let g = pureMT (fromIntegral seed)-- ------------------------------------------------------------------------- -- calibrate- s <- newMVar 0 :: IO (MVar Int)- putStr "Calibrating ... " >> hFlush stdout-- tid <- forkIO $ do- let go !i !g = do- let (!_, !g') = randomWord64 g- x <- swapMVar s i- x `seq` go (i+1) g'- go 0 g-- threadDelay (1000 * 1000)- killThread tid- lim <- readMVar s -- 1 sec worth of generation- putStrLn $ "done. Using N=" ++ show lim-- time $ do- let m = 2*lim- putStr $ "Checking against released mt19937-64.c to depth " ++ show m ++ " "- hFlush stdout- equivalent g m-- speed lim-- return ()----------------------------------------------------------------------------equivalent !g !n | n > 0 = do-- i' <- c_genrand64_int64_unsafe- d' <- c_genrand64_real2_unsafe-- let (i, g') = randomWord64 g- (d, g'') = randomDouble g'-- if i == fromIntegral i' && d == realToFrac d'- then do when (n `rem` 500000 == 0) $ putChar '.' >> hFlush stdout- equivalent g'' (n-1)-- else do print $ "Failed! " ++ show ((i,i') , (d,d'))- return g''--equivalent g _ = do putStrLn "Matches model!"- return g----------------------------------------------------------------------------- compare with System.Random---- overhead cause by random's badness-speed lim = do-- time $ do- putStrLn $ "System.Random"- let g = Old.mkStdGen 5- let go :: Old.StdGen -> Int -> Int -> Int- go !g !n !acc- | n >= lim = acc- | otherwise =- let (a, g') = Old.random g- in go g' (n+1) (if a > acc then a else acc)- print (go g 0 0)-- time $ do- putStrLn $ "System.Random with our generator"- let g = pureMT 5- let go :: PureMT -> Int -> Int -> Int- go !g !n !acc- | n >= lim = acc- | otherwise =- let (a,g') = Old.random g- in go g' (n+1) (if a > acc then a else acc)- print (go g 0 0)-- time $ do- putStrLn $ "System.Random.Mersenne.Pure"- let g = pureMT 5- let go :: PureMT -> Int -> Int -> Int- go !g !n !acc- | n >= lim = acc- | otherwise =- let (a',g') = randomWord64 g- a = fromIntegral a'- in go g' (n+1) (if a > acc then a else acc)- print (go g 0 0)-- time $ do- putStrLn $ "System.Random.Mersenne.Pure generating Double"- let g = pureMT 5- let go :: PureMT -> Int -> Double -> Double- go !g !n !acc- | n >= lim = acc- | otherwise =- let (a, g') = randomDouble g- in go g' (n+1) (if a > acc then a else acc)- print (go g 0 0)-- time $ do- putStrLn $ "System.Random.Mersenne.Pure (unique state)"- c_init_genrand64_unsafe 5- let go :: Int -> Int -> IO Int- go !n !acc- | n >= lim = return acc- | otherwise = do- a' <- c_genrand64_int64_unsafe- let a = fromIntegral a'- go (n+1) (if a > acc then a else acc)- print =<< go 0 0-- time $ do- putStrLn $ "System.Random.Mersenne.Unsafe"- g <- Unsafe.newMTGen (Just 5)-- let go :: Int -> Int -> IO Int- go !n !acc- | n >= lim = return acc- | otherwise = do- a <- Unsafe.random g- go (n+1) (if a > acc then a else acc)-- print =<< go 0 0----- printf "MT is %s times faster generating %s\n" (show $x`div`y) (show (typeOf ty))--- return ()-
− tests/copy.hs
@@ -1,15 +0,0 @@-{-# LANGUAGE BangPatterns #-}--import System.Random.Mersenne.Pure64--main = do-- let g = pureMT 7-- let go :: Int -> PureMT -> IO ()- go 0 !p = return ()- go n !p = do- let (_,q) = randomWord p- go (n-1) q-- go 10000000 g -- 10s constant space