Class
RngRandom Number Generator
Random Number Generator
All Subcl's | MersenneTwisterRng, RngFunctor |
---|---|
Defined in | <seqan/random.h> |
Signature |
template <[typename TSpec]>
class Rng;
|
Template Parameters
TSpec |
Tag for selecting the specialization. Defaults to MersenneTwisterRng. |
---|
Member Function Overview
-
TValue Rng::operator();
Function all operator.
Interface Function Overview
-
TValue pickRandomNumber(rng[, pdf]);
Pick a random number using a random number generator, possibly using a probability density function.
Interface Metafunction Overview
-
MaxValue<TRng>::VALUE;
Largest value that a Rng can return. -
MinValue<TRng>::VALUE;
Smallest value that a Rng can return. -
Value<TRng>::Type
Value type of a Rng.
Detailed Description
Examples
The following code shows how to generate random numbers and shuffle a text.
#include <iostream> #include <seqan/basic.h> #include <seqan/stream.h> #include <seqan/random.h> using namespace seqan; const int SEED = 42; int main() { Rng<MersenneTwister> rng(SEED); std::cout << "pickRandomNumber(rng) == " << pickRandomNumber(rng) << std::endl; typedef Value<Rng<MersenneTwister> >::Type TMTValue; TMTValue value = pickRandomNumber(rng); Pdf<Uniform<double> > uniformDouble(0, 1); std::cout << "pickRandomNumber(rng, uniformDouble) == " << pickRandomNumber(rng, uniformDouble) << std::endl; Pdf<Uniform<int> > uniformInt(0, 42); std::cout << "pickRandomNumber(rng, uniformInt) == " << pickRandomNumber(rng, uniformInt) << std::endl; Pdf<Normal> normal(0, 1); std::cout << "pickRandomNumber(rng, normal) == " << pickRandomNumber(rng, normal) << std::endl; Pdf<LogNormal> logNormal(0, 1); std::cout << "pickRandomNumber(rng, logNormal) == " << pickRandomNumber(rng, logNormal) << std::endl; Pdf<LogNormal> logNormal2(0, 1, MuSigma()); std::cout << "pickRandomNumber(rng, logNormal2) == " << pickRandomNumber(rng, logNormal2) << std::endl; Pdf<LogNormal> logNormal3(0.1, 1, MeanStdDev()); std::cout << "pickRandomNumber(rng, logNormal3) == " << pickRandomNumber(rng, logNormal3) << std::endl; CharString container = "Hello World!"; shuffle(container, rng); std::cout << "shuffle(\"Hello World!\") == " << container << std::endl; return 0; }
Demo: demos/random/random.cpp
pickRandomNumber(rng) == 1608637542 pickRandomNumber(rng, uniformDouble) == 0.950714 pickRandomNumber(rng, uniformInt) == 27 pickRandomNumber(rng, normal) == 0.419823 pickRandomNumber(rng, logNormal) == 1.22431 pickRandomNumber(rng, logNormal2) == 2.78004 pickRandomNumber(rng, logNormal3) == 0.00155248 shuffle("Hello World!") == o!reWlloHld
See Also
Member Functions Detail
TValue Rng::operator();
Function all operator.
Returns
TValue |
Random number, TValue can be retrieved with Rng#Value. |
---|
Interface Functions Detail
TValue pickRandomNumber(rng[, pdf]);
Pick a random number using a random number generator, possibly using a probability density function.
Parameters
rng
|
The Rng to use. |
---|---|
pdf
|
The probability density function to use. |
Returns
TValue |
A random number. TValue is the value type of the rng if pdf is not given. If pdf is given then it is of the value type of pdf. |
---|
Remarks
For more details see the SeqAn Tutorial on Randomness.