HORIZON HASKELLDocslts/ghc-10.0.x2b276322026-10-31Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 2b27632 · 2026-10-31

Modulesplitmix-0.1.3.2Haskell2010

System.Random.SplitMix32

SplitMix is a splittable pseudorandom number generator (PRNG) that is quite fast.

This is 32bit variant (original one is 32 bit).

You really don't want to use this one.

Contents
  1. Generation
  2. Initialisation
Synopsis
  • Packagesplitmix-0.1.3.2
  • Exports19
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceSplitMix32.hs
datadata SMGen

SplitMix generator state.

Instances3Read, Show, NFData
  • Read SMGenDefined in splitmix-0.1.3.2 · System.Random.SplitMix32
    Example1 expression
    readMaybe "SMGen 1 1" :: Maybe SMGenJust (SMGen 1 1)
    Example1 expression
    readMaybe "SMGen 1 2" :: Maybe SMGenNothing
    Example1 expression
    readMaybe (show (mkSMGen 42)) :: Maybe SMGenJust (SMGen 142593372 1604540297)
  • Show SMGenDefined in splitmix-0.1.3.2 · System.Random.SplitMix32
  • NFData SMGenDefined in splitmix-0.1.3.2 · System.Random.SplitMix32
valuenextWord32 :: SMGen -> (Word32, SMGen)

Generate a Word32.

Example1 expression
take 3 $ map (printf "%x") $ unfoldr (Just . nextWord32) (mkSMGen 1337) :: [String]["e0cfe722","a6ced0f0","c3a6d889"]
valuenextDouble :: SMGen -> (Double, SMGen)

Generate a Double in [0, 1) range.

Example1 expression
take 8 $ map (printf "%0.3f") $ unfoldr (Just . nextDouble) (mkSMGen 1337) :: [String]["0.878","0.764","0.063","0.845","0.262","0.490","0.176","0.544"]
valuenextFloat :: SMGen -> (Float, SMGen)

Generate a Float in [0, 1) range.

Example1 expression
take 8 $ map (printf "%0.3f") $ unfoldr (Just . nextFloat) (mkSMGen 1337) :: [String]["0.878","0.652","0.764","0.631","0.063","0.180","0.845","0.645"]

Generation

Bitmask with rejection method of generating subrange of Word64.

bitmaskWithRejection64 w64 generates random numbers in closed-open range of [0, w64).

Example1 expression
take 20 $ unfoldr (Just . bitmaskWithRejection64 5) (mkSMGen 1337)[0,2,4,2,1,4,2,4,2,2,3,0,3,2,2,2,3,1,2,2]

Bitmask with rejection method of generating subrange of Word64.

bitmaskWithRejection64' w64 generates random numbers in closed-closed range of [0, w64].

Example1 expression
take 20 $ unfoldr (Just . bitmaskWithRejection64' 5) (mkSMGen 1337)[0,2,4,2,1,4,2,4,5,5,2,2,5,3,5,0,3,2,2,2]

Initialisation

valuemkSMGen :: Word32 -> SMGen

Preferred way to deterministically construct SMGen.

Example1 expression
mkSMGen 42SMGen 142593372 1604540297