type-level-prng
Safe HaskellNone
LanguageGHC2021

Data.TypeLevel.PRNG.LCG

Description

Linear congruential generators (and Lehmer RNGs).

Synopsis

Documentation

data LCGNext (m :: Natural) (a :: Natural) (c :: Natural) (n :: FunKind Natural Natural) Source #

Calculate the next term in a linear congruential generator.

The previous term is given in n.

Instances

Instances details
type App (LCGNext m a c :: FunKind Natural Natural -> Type) (n :: Natural) Source # 
Instance details

Defined in Data.TypeLevel.PRNG.LCG

type App (LCGNext m a c :: FunKind Natural Natural -> Type) (n :: Natural) = Mod ((a * n) + c) m

type MMIX = LCGNext (2 ^ 64) 6364136223846793005 1442695040888963407 Source #

Knuth's MMIX RNG. An LCG.

As I understand, the bits have a period of 2^n where n is their bit position. So the low bits have very low randomness: e.g. it flips between odd & even! Consider only using the top 32 bits.

data LehmerNext (m :: Natural) (a :: Natural) (n :: FunKind Natural Natural) Source #

Calculate the next term in a Lehmer random number generator (a type of linear congruential generator). A type of LCG.

The previous term is given in n.

Very few operations.

Instances

Instances details
type App (LehmerNext m a :: FunKind Natural Natural -> Type) (n :: Natural) Source # 
Instance details

Defined in Data.TypeLevel.PRNG.LCG

type App (LehmerNext m a :: FunKind Natural Natural -> Type) (n :: Natural) = Mod (a * n) m

type MinstdRand = LehmerNext ((2 ^ 31) - 1) 48271 Source #

minstd_rand from C++11. A Lehmer RNG.

Seems pretty good. Low bits aren't as low period like many other LCGs.