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.Fast.Pure

Experimental pure haskell version of the fast variant of the PCG random number generator. This module can perform faster than the c bindings version, especially for parallel code.

See http://www.pcg-random.org for details.

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

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

Gen

7 declarations
newtypenewtype Gen s
#

State of the random number generator.

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

Seed with system random number. ("/dev/urandom" on Unix-like systems, time otherwise).

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
Fast.Pure.create >>= \g -> replicateM_ 1000 (uniformW32 g) >> uniformW32 g3725702568Fast.Pure.create >>= \g -> replicateM_ 500 (uniformD g) >> uniformW32 g3725702568Fast.Pure.create >>= \g -> Fast.Pure.advance 1000 g >> uniformW32 g3725702568
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
Fast.Pure.create >>= \g -> replicateM 3 (uniformW32 g)[2951688802,2698927131,361549788]Fast.Pure.create >>= \g -> Fast.Pure.retract 1 g >> replicateM 3 (uniformW32 g)[954135925,2951688802,2698927131]

Seeds

5 declarations
newtypenewtype FrozenGen
#
Instances8Eq, Data, Ord, Show, Generic, RandomGen, …

Type restricted versions

0 declarations

uniform

uniformR

uniformB