Skip to content

Expose method for initializing new StdGen from SplitMix.initSMGen #103

@Mathnerd314

Description

@Mathnerd314

From #69 it seems that the preferred method for using the library is something like

main = do
  s <- round <$> getPOSIXTime
  g <- newIOGenM $ mkStdGen s
  -- whatever thing using randomness
  l <- replicateM 10 $ uniformRM (1 :: Int, 100) g
  print l

Using POSIXTime seems hacky, when there is a nicer method of getting a random seed:

import Control.Monad
import System.Random
import System.Random.Stateful
import System.Random.Internal
import qualified System.Random.SplitMix as SM

initStdGen :: IO StdGen
initStdGen = StdGen <$> SM.initSMGen

main = do
  g <- initStdGen >>= newIOGenM
  -- whatever thing using randomness
  l <- replicateM 10 $ uniformRM (1 :: Int, 100) g
  print l

But it isn't a good idea to import internal modules, so initStdGen has to be added to the API.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions