summaryrefslogtreecommitdiff
path: root/examples/random.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2015-10-09 18:18:44 +0200
committerAlberto Ruiz <aruiz@um.es>2015-10-09 18:18:44 +0200
commit27ebc2cd08a0a65522bb571c4866aa7f41875ac3 (patch)
treecf2f43540240b3146a4ea437e11a8a30763820aa /examples/random.hs
parent7a269b14026eee91daba7eea8aacc6eff7631968 (diff)
mwc-random example (wip)
Diffstat (limited to 'examples/random.hs')
-rw-r--r--examples/random.hs23
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 @@
1import System.Random.MWC
2import qualified System.Random.MWC.Distributions as D
3import Numeric.LinearAlgebra
4import Numeric.LinearAlgebra.Devel
5
6rvec :: Vector Double
7rvec = 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
14main = 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