Class
Rng
Random Number Generator

Rng

Mersenne Twister Rng | Rng Functor

Rng<>
Rng<TSpec>
Include Headers
seqan/random.h
Parameters

TSpec | Random Number Generator specialization. Default: Mersenne Twister Rng

Specializations

Mersenne Twister Rng | Mersenne Twister 19937 Random Number Generator
Rng Functor | Functor wrapper for random number generation.

Metafunctions

MaxValue | Supremum for a given type.
MinValue | Infimum for a given type.
Value | Type of the items in the container or behind an iterator.

Member Functions

operator() | Function call operator.

Functions

pickRandomNumber | Pick a random number using a random number generator object, possibly following the given distribution.
shuffle | Shuffle the given container.

Examples
The following code shows how to generate random numbers and shuffle a text.
File "random.cpp"

1 | #include <iostream>
2 |
3 | #include <seqan/basic.h>
4 | #include <seqan/file.h>
5 | #include <seqan/random.h>
6 |
7 | using namespace seqan;
8 |
9 | const int SEED = 42;
10 |
11 | int main()
12 | {
13 | Rng<MersenneTwister> rng(SEED);
14 | std::cout << "pickRandomNumber(rng) == " << pickRandomNumber(rng) << std::endl;
15 |
16 | typedef Value<Rng<MersenneTwister> >::Type TMTValue;
17 | TMTValue value = pickRandomNumber(rng);
18 |
19 | Pdf<Uniform<double> > uniformDouble(0, 1);
20 | std::cout << "pickRandomNumber(rng, uniformDouble) == " << pickRandomNumber(rng, uniformDouble) << std::endl;
21 |
22 | Pdf<Uniform<int> > uniformInt(0, 42);
23 | std::cout << "pickRandomNumber(rng, uniformInt) == " << pickRandomNumber(rng, uniformInt) << std::endl;
24 |
25 | Pdf<Normal> normal(0, 1);
26 | std::cout << "pickRandomNumber(rng, normal) == " << pickRandomNumber(rng, normal) << std::endl;
27 |
28 | Pdf<LogNormal> logNormal(0, 1);
29 | std::cout << "pickRandomNumber(rng, logNormal) == " << pickRandomNumber(rng, logNormal) << std::endl;
30 |
31 | Pdf<LogNormal> logNormal2(0, 1, MuSigma());
32 | std::cout << "pickRandomNumber(rng, logNormal2) == " << pickRandomNumber(rng, logNormal2) << std::endl;
33 |
34 | Pdf<LogNormal> logNormal3(0.1, 1, MeanStdDev());
35 | std::cout << "pickRandomNumber(rng, logNormal3) == " << pickRandomNumber(rng, logNormal3) << std::endl;
36 |
37 | CharString container = "Hello World!";
38 | shuffle(container, rng);
39 | std::cout << "shuffle(\"Hello World!\") == " << container << std::endl;
40 |
41 | return 0;
42 | }

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
SeqAn - Sequence Analysis Library - www.seqan.de

Page built @2014/10/13 16:12:56