| Safe Haskell | None |
|---|
Crypto.Threefish.Random
Description
Skein 256 as a PRNG.
- data SkeinGen
- data Block256
- class Random a where
- class RandomGen g where
- newSkeinGen :: IO SkeinGen
- mkSkeinGen :: Serialize a => a -> SkeinGen
- mkSkeinGenEx :: Int -> Block256 -> SkeinGen
- randomBytes :: Int -> SkeinGen -> (ByteString, SkeinGen)
- reseedSkeinGen :: Block256 -> SkeinGen -> SkeinGen
- toBlock :: Threefish a b => ByteString -> Maybe a
- fromBlock :: Threefish a b => a -> ByteString
Documentation
Skein-based PRNG as defined in the Skein 1.3 paper.
Instances
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.
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:
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.
A variant of randomR that uses the global random number generator
(see System.Random).
A variant of random that uses the global random number generator
(see System.Random).
Instances
class RandomGen g where
The class RandomGen provides a common interface to random number
generators.
Methods
The next operation returns an Int that is uniformly distributed
in the range returned by genRange (including both end points),
and a new generator.
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.