Copyright | (c) Antony Courtney and Henrik Nilsson Yale University 2003 |
---|---|
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 | None |
Language | Haskell98 |
Signals and signal functions with noise and randomness.
The Random number generators are re-exported from System.Random.
Random number generators
The class RandomGen
provides a common interface to random number
generators.
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
.
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).
With a source of random number supply in hand, the Random
class allows the
programmer to extract random values of a variety of types.
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).
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 t_avg 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.