vector-random (empty) → 0.1
raw patch · 5 files changed
+154/−0 lines, 5 filesdep +basedep +mersenne-randomdep +vectorsetup-changed
Dependencies added: base, mersenne-random, vector
Files
- Data/Vector/Random/Mersenne.hs +49/−0
- LICENSE +30/−0
- Setup.hs +3/−0
- tests/test.hs +10/−0
- vector-random.cabal +62/−0
+ Data/Vector/Random/Mersenne.hs view
@@ -0,0 +1,49 @@+--------------------------------------------------------------------+-- |+-- Module : Data.Vector.Random.Mersenne+-- Copyright : (c) Don Stewart 2010++-- License : BSD3+--+-- Maintainer: Don Stewart <dons@galois.com>+-- Stability : provisional+-- Portability:+--+-- Generator for vectors of differen types+--++module Data.Vector.Random.Mersenne (random) where++import qualified System.Random.Mersenne as R++import qualified Data.Vector.Generic as G+import qualified Data.Vector.Generic.Mutable as GM++import Control.Monad.ST++-- | Return a random vector of length @n@, filled with random elements+-- of type @a@ generated by the mersenne-twister.+--+-- E.g. to compute the sum of 100 million random Double values in a vector:+--+-- > import qualified Data.Vector.Unboxed as U+-- > import System.Random.Mersenne+-- > import qualified Data.Vector.Random.Mersenne as G+-- > +-- > main = do+-- > g <- newMTGen Nothing+-- > a <- G.random g 10000000 :: IO (U.Vector Double) -- 100 M+-- > print (U.sum a)+--+random :: (R.MTRandom a, G.Vector v a) => R.MTGen -> Int -> IO (v a)+random g n = do+ v <- GM.new n+ fill v 0+ G.unsafeFreeze v+ where+ fill v i+ | i < n = do+ x <- R.random g+ GM.unsafeWrite v i x+ fill v (i+1)+ | otherwise = return ()
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Don Stewart 2010++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * 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.++ * Neither the name of Don Stewart nor the names of other+ contributors may 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.
+ Setup.hs view
@@ -0,0 +1,3 @@+#!/usr/bin/env runhaskell+import Distribution.Simple+main = defaultMain
+ tests/test.hs view
@@ -0,0 +1,10 @@++import qualified Data.Vector.Unboxed as U+import System.Random.Mersenne+import qualified Data.Vector.Random.Mersenne as G++main = do+ g <- newMTGen Nothing+ a <- G.random g 10000000 :: IO (U.Vector Double) -- 100 M+ print (U.sum a)+
+ vector-random.cabal view
@@ -0,0 +1,62 @@+-- vector-random.cabal auto-generated by cabal init. For additional+-- options, see+-- http://www.haskell.org/cabal/release/cabal-latest/doc/users-guide/authors.html#pkg-descr.+-- The name of the package.+Name: vector-random++-- The package version. See the Haskell package versioning policy+-- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for+-- standards guiding when and how versions should be incremented.+Version: 0.1++-- A short (one-line) description of the package.+Synopsis: Generate vectors filled with high quality pseudorandom numbers++-- A longer description of the package.+-- Description: ++-- URL for the project homepage or repository.+Homepage: http://code.haskell.org/~dons/code/vector-random++-- The license under which the package is released.+License: BSD3++-- The file containing the license text.+License-file: LICENSE++-- The package author(s).+Author: Don Stewart++-- An email address to which users can send suggestions, bug reports,+-- and patches.+Maintainer: dons@galois.com++-- A copyright notice.+-- Copyright: ++-- Stability of the pakcage (experimental, provisional, stable...)+Stability: Experimental++Category: Data++Build-type: Simple++-- Extra files to be distributed with the package, such as examples or+-- a README.+-- Extra-source-files: ++-- Constraint on the version of Cabal needed to build this package.+Cabal-version: >=1.2+++Library+ -- Modules exported by the library.+ Exposed-modules: + Data.Vector.Random.Mersenne+ + -- Packages needed in order to build this package.+ Build-depends: + base <= 5,+ mersenne-random,+ vector >= 0.5+