summaryrefslogtreecommitdiffstats
path: root/RandomState.hs
diff options
context:
space:
mode:
Diffstat (limited to 'RandomState.hs')
-rw-r--r--RandomState.hs14
1 files changed, 14 insertions, 0 deletions
diff --git a/RandomState.hs b/RandomState.hs
new file mode 100644
index 0000000..9466b49
--- /dev/null
+++ b/RandomState.hs
@@ -0,0 +1,14 @@
+module RandomState (splitG, splits) where
+
+import qualified Control.Monad.State as State
+import qualified System.Random as Random
+import Data.List (unfoldr)
+
+splitG :: Random.RandomGen g => State.State g g
+splitG = do g <- State.get
+ let (g1, g2) = Random.split g
+ State.put g1
+ return g2
+
+splits :: Random.RandomGen g => State.State g [g]
+splits = unfoldr (Just . Random.split) <$> splitG