Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Mathnerd314 opened this issue May 1, 2021 · 1 comment
Closed

Comments

@Mathnerd314
Copy link

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.

@lehins
Copy link
Contributor

lehins commented Jun 6, 2021

This is a perfectly sensible request IMHO.

lehins added a commit that referenced this issue Jun 6, 2021
@lehins lehins closed this as completed in 5100c52 Jun 10, 2021
lehins added a commit that referenced this issue Jun 10, 2021
lehins added a commit that referenced this issue Sep 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants