summaryrefslogtreecommitdiffstats
path: root/RandomState.hs
diff options
context:
space:
mode:
authorRay Hogenson <rhogenson@posteo.net>2019-09-07 16:36:01 -0700
committerRay Hogenson <rhogenson@posteo.net>2019-09-07 16:36:01 -0700
commit440dd38f24d1df150fb5b4c7965bb6e792c929fe (patch)
tree4d9da56e839f85949dbde1f3b3b0413f3f52b753 /RandomState.hs
downloadevolution-main.tar.zst
Write a little guyHEADmain
This program is in a weird state right now, but I'm checking it in to git so that I can back it up, since I want to reinstall again.
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