| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Crypto.Threefish.Random
Description
Skein 256 as a PRNG.
Synopsis
- data SkeinGen
- data Block256
- class Random a where
- class RandomGen g where
- next :: g -> (Int, g)
- genWord8 :: g -> (Word8, g)
- genWord16 :: g -> (Word16, g)
- genWord32 :: g -> (Word32, g)
- genWord64 :: g -> (Word64, g)
- genWord32R :: Word32 -> g -> (Word32, g)
- genWord64R :: Word64 -> g -> (Word64, g)
- genShortByteString :: Int -> g -> (ShortByteString, g)
- unsafeUniformFillMutableByteArray :: MutableByteArray s -> Int -> Int -> g -> ST s g
- genRange :: g -> (Int, Int)
- split :: g -> (g, g)
- 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
The class of types for which random values can be generated. Most
instances of Random will produce values that are uniformly distributed on the full
range, but for those types without a well-defined "full range" some sensible default
subrange will be selected.
Random exists primarily for backwards compatibility with version 1.1 of
this library. In new code, use the better specified Uniform and
UniformRange instead.
Since: random-1.0.0
Minimal complete definition
Nothing
Methods
randomR :: RandomGen g => (a, a) -> g -> (a, g) #
Takes a range (lo,hi) and a pseudo-random number generator g, and returns a pseudo-random value uniformly distributed over the closed interval [lo,hi], together with a new generator. It is unspecified what happens if lo>hi, but usually the values will simply get swapped.
>>>let gen = mkStdGen 26>>>fst $ randomR ('a', 'z') gen'z'>>>fst $ randomR ('a', 'z') gen'z'
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.
There is no requirement to follow the Ord instance and the concept of range can be
defined on per type basis. For example product types will treat their values
independently:
>>>fst $ randomR (('a', 5.0), ('z', 10.0)) $ mkStdGen 26('z',5.22694980853051)
In case when a lawful range is desired uniformR should be used
instead.
Since: random-1.0.0
default randomR :: (RandomGen g, UniformRange a) => (a, a) -> g -> (a, g) #
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 asChar), the range is normally the whole type. - For floating point types, the range is normally the closed interval
[0,1]. - For
Integer, the range is (arbitrarily) the range ofInt.
Since: random-1.0.0
randomRs :: RandomGen g => (a, a) -> g -> [a] #
Plural variant of randomR, producing an infinite list of
pseudo-random values instead of returning a new generator.
Since: random-1.0.0
randoms :: RandomGen g => g -> [a] #
Plural variant of random, producing an infinite list of
pseudo-random values instead of returning a new generator.
Since: random-1.0.0
Instances
| Random CBool | |
| Random CChar | |
| Random CDouble | Note - |
| Random CFloat | Note - |
| Random CInt | |
| Random CIntMax | |
| Random CIntPtr | |
| Random CLLong | |
| Random CLong | |
| Random CPtrdiff | |
| Random CSChar | |
| Random CShort | |
| Random CSigAtomic | |
Defined in System.Random Methods randomR :: RandomGen g => (CSigAtomic, CSigAtomic) -> g -> (CSigAtomic, g) # random :: RandomGen g => g -> (CSigAtomic, g) # randomRs :: RandomGen g => (CSigAtomic, CSigAtomic) -> g -> [CSigAtomic] # randoms :: RandomGen g => g -> [CSigAtomic] # | |
| Random CSize | |
| Random CUChar | |
| Random CUInt | |
| Random CUIntMax | |
| Random CUIntPtr | |
| Random CULLong | |
| Random CULong | |
| Random CUShort | |
| Random CWchar | |
| Random Int16 | |
| Random Int32 | |
| Random Int64 | |
| Random Int8 | |
| Random Word16 | |
| Random Word32 | |
| Random Word64 | |
| Random Word8 | |
| Random Integer | |
| Random Bool | |
| Random Char | |
| Random Double | Note - |
| Random Float | Note - |
| Random Int | |
| Random Word | |
| (Random a, Random b) => Random (a, b) | Note - |
| (Random a, Random b, Random c) => Random (a, b, c) | Note - |
| (Random a, Random b, Random c, Random d) => Random (a, b, c, d) | Note - |
| (Random a, Random b, Random c, Random d, Random e) => Random (a, b, c, d, e) | Note - |
Defined in System.Random | |
| (Random a, Random b, Random c, Random d, Random e, Random f) => Random (a, b, c, d, e, f) | Note - |
| (Random a, Random b, Random c, Random d, Random e, Random f, Random g) => Random (a, b, c, d, e, f, g) | Note - |
Defined in System.Random | |
RandomGen is an interface to pure pseudo-random number generators.
StdGen is the standard RandomGen instance provided by this library.
Since: random-1.0.0
Methods
Returns an Int that is uniformly distributed over the range returned by
genRange (including both end points), and a new generator. Using next
is inefficient as all operations go via Integer. See
here for
more details. It is thus deprecated.
Since: random-1.0.0
genWord16 :: g -> (Word16, g) #
genWord32 :: g -> (Word32, g) #
genWord64 :: g -> (Word64, g) #
genWord32R :: Word32 -> g -> (Word32, g) #
genWord32R upperBound g returns a Word32 that is uniformly
distributed over the range [0, upperBound].
Since: random-1.2.0
genWord64R :: Word64 -> g -> (Word64, g) #
genWord64R upperBound g returns a Word64 that is uniformly
distributed over the range [0, upperBound].
Since: random-1.2.0
genShortByteString :: Int -> g -> (ShortByteString, g) #
Same as , but for uniformByteArray FalseShortByteString.
genShortByteString n g returns a ShortByteString of length n filled with
pseudo-random bytes.
Note - This function will be removed from the type class in the next major release as
it is no longer needed because of unsafeUniformFillMutableByteArray.
Since: random-1.2.0
unsafeUniformFillMutableByteArray #
Arguments
| :: MutableByteArray s | Mutable array to fill with random bytes |
| -> Int | Offset into a mutable array from the beginning in number of bytes. Offset must be non-negative, but this will not be checked |
| -> Int | Number of randomly generated bytes to write into the array. Number of bytes must be non-negative and less then the total size of the array, minus the offset. This also will be checked. |
| -> g | |
| -> ST s g |
Fill in the supplied MutableByteArray with uniformly generated random bytes. This function
is unsafe because it is not required to do any bounds checking. For a safe variant use
uniformFillMutableByteArrayM instead.
Default type class implementation uses defaultUnsafeUniformFillMutableByteArray.
Since: random-1.3.0
Yields the range of values returned by next.
It is required that:
- If
(a, b) =, thengenRangega < b. genRangemust not examine its argument so the value it returns is determined only by the instance ofRandomGen.
The default definition spans the full range of Int.
Since: random-1.0.0
Returns two distinct pseudo-random number generators.
Implementations should take care to ensure that the resulting generators
are not correlated. Some pseudo-random number generators are not
splittable. In that case, the split implementation should fail with a
descriptive error message.
Since: random-1.0.0
Instances
newSkeinGen :: IO SkeinGen Source #
Create a new Skein PRNG from the system's entropy pool.
mkSkeinGen :: Serialize a => a -> SkeinGen Source #
Create a Skein PRNG from a seed.
mkSkeinGenEx :: Int -> Block256 -> SkeinGen Source #
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.
fromBlock :: Threefish a b => a -> ByteString Source #
Extract the contents of a block.