1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 // template<class _IntType = int>
12 // class uniform_int_distribution
14 // template<class _URNG> result_type operator()(_URNG& g, const param_type& parm);
22 #include "test_macros.h"
35 typedef std::uniform_int_distribution
<> D
;
36 typedef std::minstd_rand G
;
37 typedef D::param_type P
;
42 std::vector
<D::result_type
> u
;
43 for (int i
= 0; i
< N
; ++i
)
45 D::result_type v
= d(g
, p
);
46 assert(p
.a() <= v
&& v
<= p
.b());
49 double mean
= std::accumulate(u
.begin(), u
.end(),
50 double(0)) / u
.size();
54 for (std::size_t i
= 0; i
< u
.size(); ++i
)
56 double dbl
= (u
[i
] - mean
);
63 double dev
= std::sqrt(var
);
64 skew
/= u
.size() * dev
* var
;
65 kurtosis
/= u
.size() * var
* var
;
67 double x_mean
= ((double)p
.a() + p
.b()) / 2;
68 double x_var
= (sqr((double)p
.b() - p
.a() + 1) - 1) / 12;
70 double x_kurtosis
= -6. * (sqr((double)p
.b() - p
.a() + 1) + 1) /
71 (5. * (sqr((double)p
.b() - p
.a() + 1) - 1));
72 assert(std::abs((mean
- x_mean
) / x_mean
) < 0.01);
73 assert(std::abs((var
- x_var
) / x_var
) < 0.01);
74 assert(std::abs(skew
- x_skew
) < 0.01);
75 assert(std::abs((kurtosis
- x_kurtosis
) / x_kurtosis
) < 0.01);