1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // REQUIRES: long_tests
11
12 // <random>
13
14 // template<class RealType = double>
15 // class cauchy_distribution
16
17 // template<class _URNG> result_type operator()(_URNG& g);
18
19 #include <random>
20 #include <cassert>
21 #include <vector>
22 #include <algorithm>
23
24 double
f(double x,double a,double b)25 f(double x, double a, double b)
26 {
27 return 1/3.1415926535897932 * std::atan((x - a)/b) + .5;
28 }
29
main()30 int main()
31 {
32 {
33 typedef std::cauchy_distribution<> D;
34 typedef D::param_type P;
35 typedef std::mt19937 G;
36 G g;
37 const double a = 10;
38 const double b = .5;
39 D d(a, b);
40 const int N = 1000000;
41 std::vector<D::result_type> u;
42 for (int i = 0; i < N; ++i)
43 u.push_back(d(g));
44 std::sort(u.begin(), u.end());
45 for (int i = 0; i < N; ++i)
46 assert(std::abs(f(u[i], a, b) - double(i)/N) < .001);
47 }
48 {
49 typedef std::cauchy_distribution<> D;
50 typedef D::param_type P;
51 typedef std::mt19937 G;
52 G g;
53 const double a = -1.5;
54 const double b = 1;
55 D d(a, b);
56 const int N = 1000000;
57 std::vector<D::result_type> u;
58 for (int i = 0; i < N; ++i)
59 u.push_back(d(g));
60 std::sort(u.begin(), u.end());
61 for (int i = 0; i < N; ++i)
62 assert(std::abs(f(u[i], a, b) - double(i)/N) < .001);
63 }
64 {
65 typedef std::cauchy_distribution<> D;
66 typedef D::param_type P;
67 typedef std::mt19937 G;
68 G g;
69 const double a = .5;
70 const double b = 2;
71 D d(a, b);
72 const int N = 1000000;
73 std::vector<D::result_type> u;
74 for (int i = 0; i < N; ++i)
75 u.push_back(d(g));
76 std::sort(u.begin(), u.end());
77 for (int i = 0; i < N; ++i)
78 assert(std::abs(f(u[i], a, b) - double(i)/N) < .001);
79 }
80 }
81