blob: 9466b491bf95d85cfa22ff02093095eeaaf4643e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
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
|