HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulepcg-random-0.1.4.0Haskell2010

System.Random.PCG.Pure

Standard PCG Random Number Generator with chosen streams, written in pure haskell. See http://www.pcg-random.org for details.

import Control.Monad.ST
import System.Random.PCG.Pure

three :: [Double]
three = runST $ do
  g <- create
  a <- uniform g
  b <- uniform g
  c <- uniform g
  return [a,b,c]
  • 5 types
  • 1 class
  • 45 values

Gen

7 declarations
newtypenewtype Gen s
#

State of the random number generator

Instances1Generator

Seed with system random number. (/dev/urandom on Unix-like systems and CryptAPI on Windows).

valuewithSystemRandom :: (GenIO -> IO a) -> IO a
#

Seed with system random number. (/dev/urandom on Unix-like systems and CryptAPI on Windows).

Getting random numbers

3 declarations
classclass Variate a where
#

Methods

  • uniform :: Generator g m => g -> m a

    Generate a uniformly distributed random vairate.

    • Use entire range for integral types.

    • Use (0,1] range for floating types.

  • uniformR :: Generator g m => (a, a) -> g -> m a

    Generate a uniformly distributed random vairate in the given range.

    • Use inclusive range for integral types.

    • Use (a,b] range for floating types.

  • uniformB :: Generator g m => a -> g -> m a

    Generate a uniformly distributed random vairate in the range [0,b). For integral types the bound must be less than the max bound of Word32 (4294967295). Behaviour is undefined for negative bounds.

Instances16Variate, …
  • Variate Int16Defined in pcg-random-0.1.4.0 · System.Random.PCG.Class
  • Variate Int32Defined in pcg-random-0.1.4.0 · System.Random.PCG.Class
  • Variate Int64Defined in pcg-random-0.1.4.0 · System.Random.PCG.Class
  • Variate Int8Defined in pcg-random-0.1.4.0 · System.Random.PCG.Class
  • Variate Word16Defined in pcg-random-0.1.4.0 · System.Random.PCG.Class
  • Variate Word32Defined in pcg-random-0.1.4.0 · System.Random.PCG.Class
  • Variate Word64Defined in pcg-random-0.1.4.0 · System.Random.PCG.Class
  • Variate Word8Defined in pcg-random-0.1.4.0 · System.Random.PCG.Class
  • Variate BoolDefined in pcg-random-0.1.4.0 · System.Random.PCG.Class
  • Variate DoubleDefined in pcg-random-0.1.4.0 · System.Random.PCG.Class
  • Variate FloatDefined in pcg-random-0.1.4.0 · System.Random.PCG.Class
  • Variate IntDefined in pcg-random-0.1.4.0 · System.Random.PCG.Class
  • Variate WordDefined in pcg-random-0.1.4.0 · System.Random.PCG.Class
  • (Variate a, Variate b) => Variate (a, b)Defined in pcg-random-0.1.4.0 · System.Random.PCG.Class
  • (Variate a, Variate b, Variate c) => Variate (a, b, c)Defined in pcg-random-0.1.4.0 · System.Random.PCG.Class
  • (Variate a, Variate b, Variate c, Variate d) => Variate (a, b, c, d)Defined in pcg-random-0.1.4.0 · System.Random.PCG.Class
valueadvance :: PrimMonad m => Word64 -> Gen (PrimState m) -> m ()
#

Advance the given generator n steps in log(n) time. (Note that a "step" is a single random 32-bit (or less) Variate. Data types such as Double or Word64 require two "steps".)

Example3 expressions
Pure.create >>= \g -> replicateM_ 1000 (uniformW32 g) >> uniformW32 g3640764222Pure.create >>= \g -> replicateM_ 500 (uniformD g) >> uniformW32 g3640764222Pure.create >>= \g -> Pure.advance 1000 g >> uniformW32 g3640764222
valueretract :: PrimMonad m => Word64 -> Gen (PrimState m) -> m ()
#

Retract the given generator n steps in log(2^64-n) time. This is just advance (-n).

Example2 expressions
Pure.create >>= \g -> replicateM 3 (uniformW32 g)[355248013,41705475,3406281715]Pure.create >>= \g -> Pure.retract 1 g >> replicateM 3 (uniformW32 g)[19683962,355248013,41705475]

Seeds

5 declarations
valueinitFrozen :: Word64 -> Word64 -> SetSeq
#

Create a new generator from two words.

Example1 expression
Pure.initFrozen 0 0SetSeq 6364136223846793006 1

Type restricted versions

0 declarations

uniform

uniformR

uniformB

Pure

3 declarations
datadata SetSeq
#

The multiple sequence varient of the pcg random number generator.

Instances8Eq, Data, Ord, Show, Generic, Storable, …