real-dice-0.1.0.2: Random number generation based on physical media touched by humans
Safe HaskellSafe-Inferred
LanguageGHC2021

RealDice.RNG

Description

This module provides functions to generate random numbers using balanced integer tables randomized by the RealDice data or custom integer tables

Synopsis

Documentation

data RDGen Source #

Stores a balanced table of random integers and an index pointing to the next value to return

randomIntR :: (Int, Int) -> RDGen -> (Int, RDGen) Source #

Generates a random integer value between minResult and maxResult via a simple table lookup

Examples

Expand
>>> randomIntR (1, 20) (mkRDGen 143)
(12, {144, rdIntsPrime})
>>> randomIntR (-1000000, 1000000) (mkRDGen 42)
(76465, {43, rdIntsPrime})
>>> randomIntR (10, 1) (mkRDGen 42)
(0, {43, rdIntsPrime})

randomFloat :: Int -> RDGen -> (Float, RDGen) Source #

Examples

Expand
>>> randomFloat 3 (mkRDGen 143)
(0.503, {144, rdIntsPrime})
>>> randomFloat 0 (mkRDGen 143)
(0, {143, rdIntsPrime})
>>> randomFloat (-1) (mkRDGen 143)
(0, {143, rdIntsPrime})

randomDouble :: Int -> RDGen -> (Double, RDGen) Source #

Examples

Expand
>>> randomDouble 3 (mkRDGen 143)
(0.503, {144, rdIntsPrime})
>>> randomDouble 0 (mkRDGen 143)
(0, {143, rdIntsPrime})
>>> randomDouble (-1) (mkRDGen 143)
(0, {143, rdIntsPrime})

mkRDGen :: Int -> RDGen Source #

Creates a new RDGen with the given index and the default Int table

Examples

Expand
>>> mkRDGen 143
{143, rdIntsPrime}

mkRDGenCustom :: Int -> [Int] -> RDGen Source #

Creates a new RDGen with the given index and Int table

Defaults to the RealDice balanced table of random integers if an empty list is given

Examples

Expand
>>> mkRDGenCustom 143 [1, 0, 4, 3, 2]
{143, [1, 0, 4, 3, 2]}
>>> mkRDGenCustom 143 []
{143, rdIntsPrime}