Copyright | (c) Ivan Perez 2014-2022 (c) George Giorgidze 2007-2012 (c) Henrik Nilsson 2005-2006 (c) Antony Courtney and Henrik Nilsson Yale University 2003-2004 |
---|---|
License | BSD-style (see the LICENSE file in the distribution) |
Maintainer | ivan.perez@keera.co.uk |
Stability | provisional |
Portability | non-portable (GHC extensions) |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Signals and signal functions with noise and randomness.
The Random number generators are re-exported from System.Random.
Synopsis
- 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)
- genRange :: g -> (Int, Int)
- split :: g -> (g, g)
- class Random a where
- noise :: (RandomGen g, Random b) => g -> SF a b
- noiseR :: (RandomGen g, Random b) => (b, b) -> g -> SF a b
- occasionally :: RandomGen g => g -> Time -> b -> SF a (Event b)
Random number generators
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
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) #
genShortByteString n g
returns a ShortByteString
of length n
filled with pseudo-random bytes.
Since: random-1.2.0
Yields the range of values returned by next
.
It is required that:
- If
(a, b) =
, thengenRange
ga < b
. genRange
must 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
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
Nothing
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 2021
>>>
fst $ randomR ('a', 'z') gen
't'>>>
fst $ randomR ('z', 'a') gen
't'
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 2021
('t',6.240232662366563)
In case when a lawful range is desired uniformR
should be used
instead.
Since: random-1.0.0
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 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 |
Noise, random signals, and stochastic event sources
noise :: (RandomGen g, Random b) => g -> SF a b Source #
Noise (random signal) with default range for type in question; based on "randoms".
noiseR :: (RandomGen g, Random b) => (b, b) -> g -> SF a b Source #
Noise (random signal) with specified range; based on "randomRs".
occasionally :: RandomGen g => g -> Time -> b -> SF a (Event b) Source #
Stochastic event source with events occurring on average once every tAvg seconds. However, no more than one event results from any one sampling interval in the case of relatively sparse sampling, thus avoiding an "event backlog" should sampling become more frequent at some later point in time.