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.Unique

Unique variant of the PCG random number generator. Guarantees the sequence to be unique by using the pointer address to select the output sequence.

There is no way to freeze the state because then it wouldn't be unique anymore. Also, generators can't be initialized in ST because we don't know what pointer reference they'll get.

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

import System.Random.PCG.Unique

three :: IO [Double]
three = do
  g <- create
  a <- uniform g
  b <- uniform g
  c <- uniform g
  return [a,b,c]
  • 1 type
  • 1 class
  • 39 values

Gen

5 declarations
newtypenewtype Gen
#

State of the random number generator

Instances3Eq, Ord, Generator
  • Eq GenDefined in pcg-random-0.1.4.0 · System.Random.PCG.Unique
  • Ord GenDefined in pcg-random-0.1.4.0 · System.Random.PCG.Unique
  • Generator Gen IODefined in pcg-random-0.1.4.0 · System.Random.PCG.Unique
valueinitialize :: Word64 -> IO Gen
#

Create a generator from two words. Note: this is not the same as the two words in a Seed.

valuewithSystemRandom :: (Gen -> 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 :: Word64 -> Gen -> IO ()
#

Advance the given generator n steps in log(n) time.

valueretract :: Word64 -> Gen -> IO ()
#

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

Type restricted versions

0 declarations

uniform

uniformR

uniformB