Module System.Random

This module deals with the common task of pseudo-random number generation.

It is possible to generate repeatable results, by starting with a specified initial random number, or to get different results on each run by using a generator that gets seeded in a system-dependent random way, or by supplying a seed from some other source.

In Frege, the underlying mechanism for actually generating random numbers is provided by J.Random. Consequently, one cannot expect that a random generator seeded with a certain value will generate the same sequence of random numbers as its Haskell counterpart.

Imports

Table of Content

Definitions

class RandomGen g

The class RandomGen provides a common interface to random number generators.

Known Instances

StdGen

Member Functions

genRangeRandomGen g ⇒ g → (Int, Int)

Gives the full range of the random generator, which must not depend on the state of the generator, but only on its type.

The default definition is (Bounded_Int.minBound, Bounded_Int.maxBound)

nextRandomGen g ⇒ g → (Int, g)

The next operation returns an Int that is uniformly distributed in the range returned by genRange (including both end points), and a new generator.

nextBoolRandomGen g ⇒ g → (Bool, g)

Returns an uniformly distributed Bool and a new generator.

nextDoubleRandomGen g ⇒ g → (Double, g)

Returns a random Double d with 0<=d<1 and a new generator.

nextLongRandomGen g ⇒ g → (Long, g)

Returns an uniformly distributed Long and a new generator.

splitRandomGen g ⇒ g → (g, g)

The split operation allows one to obtain two distinct random number generators. This is very useful in functional programs (for example, when passing a random number generator down to recursive calls), but very little work has been done on statistically robust implementations.

data StdGen

Standard random number generator

Constructors

private StdGen Long

Member Functions

makeLongStdGen

The function StdGen.make provides a way of producing an initial generator, by mapping an Int into a generator.

Distinct arguments should be likely to produce distinct generators.

setGlobalStdGenIO ()

set the global random number generator

mkStdGenIntStdGen

Make an initial generator based on an Int seed.

getStdGenIO StdGen

The global random generator.

setStdGenStdGenIO ()

Alias for StdGen.setGlobal

getStdRandom ∷ (StdGen→(𝖆, 𝖇)) → IO 𝖆
newStdGenIO StdGen

Applies RandomGen.split to the current global random generator, updates it with one of the results, and returns the other.

class Random r

Known Instances

Int, Bool, Double, Float, Long, Integer

Member Functions

random ∷ (Random r, RandomGen g) ⇒ g → (r, g)

a random value

randomIORandom r ⇒ IO r

a random value from the global generator

randomR ∷ (Random r, RandomGen g) ⇒ (r, r) → g → (r, g)

a random value in the given bounds

randomRIORandom r ⇒ (r, r) → IO r

a random value in the given bounds from the global generator

randomRs ∷ (Random r, RandomGen g) ⇒ (r, r) → g → [r]

a list of random values in the given bound

randoms ∷ (Random r, RandomGen g) ⇒ g → [r]

a list of random values

Instances

instance RandomGen StdGen

The StdGen instance of RandomGen delegates random number generation to an instance of J.Random.

Member Functions

genRangeStdGen → (Int, Int)

inherited from RandomGen.genRange

nextStdGen → (Int, StdGen)

get the next Int and a new generator

nextBoolStdGen → (Bool, StdGen)
nextDoubleStdGen → (Double, StdGen)
nextLongStdGen → (Long, StdGen)
splitStdGen → (StdGen, StdGen)

Make two independent generators, seeded by two Long values drawn from the argument

instance Random Bool

Member Functions

randomRandomGen 𝖆 ⇒ 𝖆 → (Bool, 𝖆)
randomIOIO Bool

inherited from Random.randomIO

randomRRandomGen 𝖆 ⇒ (Bool, Bool) → 𝖆 → (Bool, 𝖆)
randomRIO(Bool, Bool)IO Bool

inherited from Random.randomRIO

randomRsRandomGen 𝖆 ⇒ (Bool, Bool) → 𝖆 → [Bool]

inherited from Random.randomRs

randomsRandomGen 𝖆 ⇒ 𝖆 → [Bool]

inherited from Random.randoms

instance Random Double

Member Functions

randomRandomGen 𝖆 ⇒ 𝖆 → (Double, 𝖆)
randomIOIO Double

inherited from Random.randomIO

randomRRandomGen 𝖆 ⇒ (Double, Double) → 𝖆 → (Double, 𝖆)
randomRIO(Double, Double)IO Double

inherited from Random.randomRIO

randomRsRandomGen 𝖆 ⇒ (Double, Double) → 𝖆 → [Double]

inherited from Random.randomRs

randomsRandomGen 𝖆 ⇒ 𝖆 → [Double]

inherited from Random.randoms

instance Random Float

Member Functions

randomRandomGen 𝖆 ⇒ 𝖆 → (Float, 𝖆)
randomIOIO Float

inherited from Random.randomIO

randomRRandomGen 𝖆 ⇒ (Float, Float) → 𝖆 → (Float, 𝖆)
randomRIO(Float, Float)IO Float

inherited from Random.randomRIO

randomRsRandomGen 𝖆 ⇒ (Float, Float) → 𝖆 → [Float]

inherited from Random.randomRs

randomsRandomGen 𝖆 ⇒ 𝖆 → [Float]

inherited from Random.randoms

instance Random Int

Member Functions

randomRandomGen 𝖆 ⇒ 𝖆 → (Int, 𝖆)
randomIOIO Int

inherited from Random.randomIO

randomRRandomGen 𝖆 ⇒ (Int, Int) → 𝖆 → (Int, 𝖆)
randomRIO(Int, Int)IO Int

inherited from Random.randomRIO

randomRsRandomGen 𝖆 ⇒ (Int, Int) → 𝖆 → [Int]

inherited from Random.randomRs

randomsRandomGen 𝖆 ⇒ 𝖆 → [Int]

inherited from Random.randoms

instance Random Integer

Member Functions

randomRandomGen 𝖆 ⇒ 𝖆 → (Integer, 𝖆)
randomIOIO Integer

inherited from Random.randomIO

randomRRandomGen 𝖆 ⇒ (Integer, Integer) → 𝖆 → (Integer, 𝖆)

For the interval (Long.minBound, Long.maxBound), just the converted Long value is returned.

For any other interval, some non-negative Long value not greater than the difference between the upper and the lower bound is added to the lower bound.

randomRIO(Integer, Integer)IO Integer

inherited from Random.randomRIO

randomRsRandomGen 𝖆 ⇒ (Integer, Integer) → 𝖆 → [Integer]

inherited from Random.randomRs

randomsRandomGen 𝖆 ⇒ 𝖆 → [Integer]

inherited from Random.randoms

instance Random Long

Member Functions

randomRandomGen 𝖆 ⇒ 𝖆 → (Long, 𝖆)
randomIOIO Long

inherited from Random.randomIO

randomRRandomGen 𝖆 ⇒ (Long, Long) → 𝖆 → (Long, 𝖆)

We allow only intervals from (Long.minBound `div` 2) to (Long.maxBound `div` 2) with the exception (Long.minBound, Long.maxBound), which is allowed.

randomRIO(Long, Long)IO Long

inherited from Random.randomRIO

randomRsRandomGen 𝖆 ⇒ (Long, Long) → 𝖆 → [Long]

inherited from Random.randomRs

randomsRandomGen 𝖆 ⇒ 𝖆 → [Long]

inherited from Random.randoms

Functions and Values by Type

(Bool, Bool) → IO Bool

Random_Bool.randomRIO

(Double, Double) → IO Double

Random_Double.randomRIO

(Float, Float) → IO Float

Random_Float.randomRIO

(Int, Int) → IO Int

Random_Int.randomRIO

(Integer, Integer) → IO Integer

Random_Integer.randomRIO

(Long, Long) → IO Long

Random_Long.randomRIO

IntStdGen

mkStdGen

LongStdGen

StdGen.StdGen, StdGen.make

StdGen → (Bool, StdGen)

RandomGen_StdGen.nextBool

StdGen → (Double, StdGen)

RandomGen_StdGen.nextDouble

StdGen → (Int, Int)

RandomGen_StdGen.genRange

StdGen → (Int, StdGen)

RandomGen_StdGen.next

StdGen → (Long, StdGen)

RandomGen_StdGen.nextLong

StdGen → (StdGen, StdGen)

RandomGen_StdGen.split

StdGenIO ()

StdGen.setGlobal

IO Bool

Random_Bool.randomIO

IO Double

Random_Double.randomIO

IO Float

Random_Float.randomIO

IO Int

Random_Int.randomIO

IO Integer

Random_Integer.randomIO

IO Long

Random_Long.randomIO

IO StdGen

getStdGen, newStdGen

Random r ⇒ (r, r) → IO r

Random.randomRIO

RandomGen g ⇒ g → (Bool, g)

RandomGen.nextBool

RandomGen g ⇒ g → (Double, g)

RandomGen.nextDouble

RandomGen g ⇒ g → (Int, Int)

RandomGen.genRange

RandomGen g ⇒ g → (Int, g)

RandomGen.next

RandomGen g ⇒ g → (Long, g)

RandomGen.nextLong

RandomGen g ⇒ g → (g, g)

RandomGen.split

RandomGen 𝖆 ⇒ (Bool, Bool) → 𝖆 → (Bool, 𝖆)

Random_Bool.randomR

RandomGen 𝖆 ⇒ (Bool, Bool) → 𝖆 → [Bool]

Random_Bool.randomRs

RandomGen 𝖆 ⇒ (Double, Double) → 𝖆 → (Double, 𝖆)

Random_Double.randomR

RandomGen 𝖆 ⇒ (Double, Double) → 𝖆 → [Double]

Random_Double.randomRs

RandomGen 𝖆 ⇒ (Float, Float) → 𝖆 → (Float, 𝖆)

Random_Float.randomR

RandomGen 𝖆 ⇒ (Float, Float) → 𝖆 → [Float]

Random_Float.randomRs

RandomGen 𝖆 ⇒ (Int, Int) → 𝖆 → (Int, 𝖆)

Random_Int.randomR

RandomGen 𝖆 ⇒ (Int, Int) → 𝖆 → [Int]

Random_Int.randomRs

RandomGen 𝖆 ⇒ (Integer, Integer) → 𝖆 → (Integer, 𝖆)

Random_Integer.randomR

RandomGen 𝖆 ⇒ (Integer, Integer) → 𝖆 → [Integer]

Random_Integer.randomRs

RandomGen 𝖆 ⇒ (Long, Long) → 𝖆 → (Long, 𝖆)

Random_Long.randomR

RandomGen 𝖆 ⇒ (Long, Long) → 𝖆 → [Long]

Random_Long.randomRs

RandomGen 𝖆 ⇒ 𝖆 → (Bool, 𝖆)

Random_Bool.random

RandomGen 𝖆 ⇒ 𝖆 → (Double, 𝖆)

Random_Double.random

RandomGen 𝖆 ⇒ 𝖆 → (Float, 𝖆)

Random_Float.random

RandomGen 𝖆 ⇒ 𝖆 → (Int, 𝖆)

Random_Int.random

RandomGen 𝖆 ⇒ 𝖆 → (Integer, 𝖆)

Random_Integer.random

RandomGen 𝖆 ⇒ 𝖆 → (Long, 𝖆)

Random_Long.random

RandomGen 𝖆 ⇒ 𝖆 → [Bool]

Random_Bool.randoms

RandomGen 𝖆 ⇒ 𝖆 → [Double]

Random_Double.randoms

RandomGen 𝖆 ⇒ 𝖆 → [Float]

Random_Float.randoms

RandomGen 𝖆 ⇒ 𝖆 → [Int]

Random_Int.randoms

RandomGen 𝖆 ⇒ 𝖆 → [Integer]

Random_Integer.randoms

RandomGen 𝖆 ⇒ 𝖆 → [Long]

Random_Long.randoms

Random r ⇒ IO r

Random.randomIO

(StdGen→(𝖆, 𝖇)) → IO 𝖆

getStdRandom

(Random r, RandomGen g) ⇒ (r, r) → g → (r, g)

Random.randomR

(Random r, RandomGen g) ⇒ (r, r) → g → [r]

Random.randomRs

(Random r, RandomGen g) ⇒ g → (r, g)

Random.random

(Random r, RandomGen g) ⇒ g → [r]

Random.randoms

Valid HTML 4.01 Strict