MyNixOS website logo
Description

A pure Haskell PRNG.

This is a psuedo-random number generator (PRNG). It is designed to replace the standard Haskell '98 PRNG from the random package. It has the following properties:

  • Nicer API than random. (Supports all sizes of Int and Word, for example.)

  • Much faster than random. (In my tests, roughly 14x faster.)

  • Comparable quality to random. (Both libraries pass the "Die Harder" suite of statistical randomness tests. In other words, neither has any overly obvious pattern to the "random" numbers it produces. Both libraries pass Die Harder with similar scores.)

  • 100% Haskell '98 code. No compiler-specific features. No external dependencies. Builds everywhere.

  • Pure functions and simple ADTs. No mutable state, no IO monad. Simple API.

The actual algorithm is a lag-4 Multiply With Carry (MWC) generator, using 32-bit arithmetic. (Should be fast on 32-bit and 64-bit platforms.) If my algebra is correct, its period should be roughly 1.46 * 10^48. (By constrast, random claims to have a period of only 2.30 * 10^18.)

Note that this algorithm, by itself, is not cryptographically secure.

Changes:

  • Initial release.

Metadata

Version

0.1

Platforms (77)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows