Class Rng
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

Interface Function Overview

Interface Metafunction Overview

Detailed Description


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;
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.


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.


rng The Rng to use.
pdf The probability density function to use.


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.


For more details see the SeqAn Tutorial on Randomness.

Interface Metafunctions Detail


Largest value that a Rng can return.

Template Parameters

TRng The Rng object to get the largest value for.


VALUE The largest value a Rng can return.


Smallest value that a Rng can return.

Template Parameters

TRng The Rng object to get the smallest value for.


VALUE The smallest value a Rng can return.


Value type of a Rng.

Template Parameters

TRng the Rng to get the value type for.


Type the value type for the Rng.