diff options
author | Alberto Ruiz <aruiz@um.es> | 2015-10-09 18:18:44 +0200 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2015-10-09 18:18:44 +0200 |
commit | 27ebc2cd08a0a65522bb571c4866aa7f41875ac3 (patch) | |
tree | cf2f43540240b3146a4ea437e11a8a30763820aa /examples/random.hs | |
parent | 7a269b14026eee91daba7eea8aacc6eff7631968 (diff) |
mwc-random example (wip)
Diffstat (limited to 'examples/random.hs')
-rw-r--r-- | examples/random.hs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/examples/random.hs b/examples/random.hs new file mode 100644 index 0000000..9be8eca --- /dev/null +++ b/examples/random.hs | |||
@@ -0,0 +1,23 @@ | |||
1 | import System.Random.MWC | ||
2 | import qualified System.Random.MWC.Distributions as D | ||
3 | import Numeric.LinearAlgebra | ||
4 | import Numeric.LinearAlgebra.Devel | ||
5 | |||
6 | rvec :: Vector Double | ||
7 | rvec = runSTVector $ do | ||
8 | v <- newUndefinedVector 10 | ||
9 | g <- initialize (fromList [4, 8, 15, 16, 23, 42]) | ||
10 | mapM_ (\k -> writeVector v k =<< D.standard g) [0..9] | ||
11 | return v | ||
12 | |||
13 | |||
14 | main = do | ||
15 | v <- withSystemRandom . asGenST $ \gen -> uniformVector gen 20 | ||
16 | print (v :: Vector Double) | ||
17 | |||
18 | g <- initialize (fromList [4, 8, 15, 16, 23, 42]) | ||
19 | x <- uniform g :: IO Double | ||
20 | print x | ||
21 | print =<< (uniform g :: IO Double) | ||
22 | print =<< (uniformVector g 20 :: IO (Vector Double)) | ||
23 | |||