Proposal: Add getStdGenState and stdGenFromState

Bas van Dijk v.dijk.bas at gmail.com
Mon Feb 6 19:14:41 CET 2012


On 6 February 2012 18:58, John Meacham <john at repetae.net> wrote:
> 64 bits of entropy doesn't seem like much at all for a RNG. I thought
> the idea was StdGen could be fully abstract.

Well it's still sort of abstract since its constructor is not
exported. My idea was that since StdGen already has a Read and Show
instance we can just as well provide a more efficient serialization
method.

But I agree that the API should accommodate for changing the amount of
bits. What about the following API:

getStdGenState :: StdGen -> [Int32]
getStdGenState (StdGen s1 s2) = [s1, s2]

stdGenFromState :: [Int32] -> Maybe StdGen
stdGenFromState [s1, s2] = Just (StdGen s1 s2)
stdGenFromState _        = Nothing

Bas



More information about the Libraries mailing list