summaryrefslogtreecommitdiffstats
path: root/libcxx/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/eval_param.pass.cpp
blob: 9727949a48a3f797dd50bd84972e84859ff6e67d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//===----------------------------------------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

// <random>

// template<class IntType = int>
// class binomial_distribution

// template<class _URNG> result_type operator()(_URNG& g, const param_type& parm);

#include <random>
#include <cassert>

#include <iostream>

int main()
{
    {
        typedef std::binomial_distribution<> D;
        typedef D::param_type P;
        typedef std::minstd_rand0 G;
        G g;
        D d(16, .75);
        P p(16, .25);
        int count = 0;
        int r = 0;
        for (int i = 0; i < 100; ++i)
        {
            D::result_type u = d(g, p);
            r += u;
        }
        assert(int(r/100. + .5) == 4);
    }
    {
        typedef std::binomial_distribution<> D;
        typedef D::param_type P;
        typedef std::minstd_rand0 G;
        G g;
        D d(16, .75);
        P p(16, .5);
        int count = 0;
        int r = 0;
        for (int i = 0; i < 100; ++i)
        {
            D::result_type u = d(g, p);
            r += u;
        }
        assert(int(r/100. + .5) == 8);
    }
    {
        typedef std::binomial_distribution<> D;
        typedef D::param_type P;
        typedef std::minstd_rand0 G;
        G g;
        D d(16, .75);
        P p(16, .75);
        int count = 0;
        int r = 0;
        for (int i = 0; i < 100; ++i)
        {
            D::result_type u = d(g, p);
            r += u;
        }
        assert(int(r/100. + .5) == 12);
    }
}
OpenPOWER on IntegriCloud