diff options
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 | |||