-
Notifications
You must be signed in to change notification settings - Fork 57
Open
Description
There are RNGs that can skip n values in less than O(n) time, and they should have the opportunity to expose this to the user. And the ones that don't still have a sensible default:
skip :: (RandomGen g) => Int -> g -> g
skip n g | n <= 0 = g
skip n g = case next g of (_, g') -> skip (n - 1) g'
There are also RNGs that allow the user to mix in entropy to the generator, and this also has a sensible default for generators without that operation:
pick :: Bool -> (a, a) -> a
pick False (f, s) = f
pick True (f, s) = s
mix :: (RandomGen g) => Int -> g -> g
mix = go (finiteBitSize (0 :: Int)) where
go n k g | n `seq` k `seq` g `seq` False = undefined
go n k g | n < 0 = g
go n k g = go (n - 1) k (testBit K n `pick` split g)
These methods should be part of the typeclass so they can be available to both consumers of random numbers and those who want to create generators that modify other generators.
Metadata
Metadata
Assignees
Labels
No labels