threefish-0.2.6: The Threefish block cipher and the Skein hash function for Haskell.

Safe HaskellNone

Crypto.Threefish.Random

Description

Skein 256 as a PRNG.

Synopsis

Documentation

data SkeinGen Source

Skein-based PRNG as defined in the Skein 1.3 paper.

class Random a where

With a source of random number supply in hand, the Random class allows the programmer to extract random values of a variety of types.

Minimal complete definition: randomR and random.

Methods

randomR :: RandomGen g => (a, a) -> g -> (a, g)

Takes a range (lo,hi) and a random number generator g, and returns a random value uniformly distributed in the closed interval [lo,hi], together with a new generator. It is unspecified what happens if lo>hi. For continuous types there is no requirement that the values lo and hi are ever produced, but they may be, depending on the implementation and the interval.

random :: RandomGen g => g -> (a, g)

The same as randomR, but using a default range determined by the type:

  • For bounded types (instances of Bounded, such as Char), the range is normally the whole type.
  • For fractional types, the range is normally the semi-closed interval [0,1).
  • For Integer, the range is (arbitrarily) the range of Int.

randomRs :: RandomGen g => (a, a) -> g -> [a]

Plural variant of randomR, producing an infinite list of random values instead of returning a new generator.

randoms :: RandomGen g => g -> [a]

Plural variant of random, producing an infinite list of random values instead of returning a new generator.

randomRIO :: (a, a) -> IO a

A variant of randomR that uses the global random number generator (see System.Random).

randomIO :: IO a

A variant of random that uses the global random number generator (see System.Random).

class RandomGen g where

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

Methods

next :: 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.

genRange :: g -> (Int, Int)

The genRange operation yields the range of values returned by the generator.

It is required that:

The second condition ensures that genRange cannot examine its argument, and hence the value it returns can be determined only by the instance of RandomGen. That in turn allows an implementation to make a single call to genRange to establish a generator's range, without being concerned that the generator returned by (say) next might have a different range to the generator passed to next.

The default definition spans the full range of Int.

split :: 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 of split ([System.Random, System.Random] are the only examples we know of).

newSkeinGen :: IO SkeinGenSource

Create a new Skein PRNG from the system's entropy pool.

mkSkeinGen :: Serialize a => a -> SkeinGenSource

Create a Skein PRNG from a seed.

mkSkeinGenEx :: Int -> Block256 -> SkeinGenSource

Create a Skein PRNG with a custom pool size. Larger pool sizes give faster random data, but obviously take up more memory. Pool size is preserved across splits.

randomBytes :: Int -> SkeinGen -> (ByteString, SkeinGen)Source

Generate n random bytes using the given generator.

reseedSkeinGen :: Block256 -> SkeinGen -> SkeinGenSource

Reseed a Skein PRNG.

toBlock :: Threefish a b => ByteString -> Maybe aSource

Create an appropriately sized block.

fromBlock :: Threefish a b => a -> ByteStringSource

Extract the contents of a block.