I see strange behavior using C ++ 11 compilation std::uniform_real_distributionwith Apple LLVM version 7.0.2 (clang-700.1.81). An operator call () takes results outside the distribution range. The minimum sample program below reproduces the problem.
#include <random>
#include <iostream>
#include <string>
template< int power >
constexpr uint64_t power_of_two(){
return 2 * power_of_two< power - 1 >();
}
template< >
constexpr uint64_t power_of_two< 0 >(){
return 1;
}
std::linear_congruential_engine
< uint64_t, 273673163155, 13, power_of_two< 48 >() >
rng;
std::uniform_real_distribution< double > angle_cosine(-1, 1);
int main()
{
std::cout << angle_cosine.a() << " " << angle_cosine.b() << '\n' << std::endl;
for (int i = 0; i < 4; ++i){
std::cout << angle_cosine(rng) << std::endl;
}
}
Compiling and running online (presumably with g ++) yields reasonable results
-1 1
-0.529254
-0.599452
0.513316
-0.604338
However, compiling and running locally gives unreasonable results.
-1 1
130349
37439.4
42270.5
45335.4
Am I missing something or encountering an error in libC ++? If so, does anyone know about work?
source
share