{-# LANGUAGE ScopedTypeVariables #-}
module ELynx.Tools.Concurrent
(
splitGen,
getChunks,
)
where
import Control.Monad
import Control.Monad.Primitive
import qualified Data.Vector as V
import Data.Word
import System.Random.MWC
splitGen :: PrimMonad m => Int -> Gen (PrimState m) -> m [Gen (PrimState m)]
splitGen n gen
| n <= 0 = return []
| otherwise = do
seeds :: [V.Vector Word32] <- replicateM (n -1) $ uniformVector gen 256
fmap (gen :) (mapM initialize seeds)
getChunks :: Int -> Int -> [Int]
getChunks c n = ns
where
n' = n `div` c
r = n `mod` c
ns = replicate r (n' + 1) ++ replicate (c - r) n'