Ticket #7779: bug_uniform_on_sphere.cpp

File bug_uniform_on_sphere.cpp, 1.5 KB (added by Robert Gantner <rngantner@…>, 10 years ago)

Program recreating uniform_on_sphere bug.

Line 
1#include <boost/circular_buffer.hpp>
2#include <boost/random/variate_generator.hpp>
3#include <boost/random/uniform_on_sphere.hpp>
4#include <boost/random.hpp>
5#include <iostream>
6#include <fstream>
7using namespace std;
8
9int main(int argc, const char *argv[])
10{
11 typedef boost::mt19937 GeneratorType;
12 typedef boost::uniform_on_sphere<float> DistributionType;
13 typedef boost::variate_generator<GeneratorType, DistributionType > VariateType;
14 typedef boost::circular_buffer<DistributionType::result_type> BufferType;
15 const int BUFSIZE = 10;
16 const int DIM = 2;
17 GeneratorType gen;
18 DistributionType dist(DIM);
19 VariateType variate(gen,dist);
20
21 gen.seed(11);
22 BufferType buf(BUFSIZE);
23 long n(0);
24 DistributionType::result_type tmp;
25 while (1){
26 cout << "n: " << n << "\r" << flush;
27 tmp = variate();
28 buf.push_back(tmp);
29 if (isnan(tmp[0])) {
30 cout << "n: " << n << " " << endl;
31 for (size_t i=0; i<DIM; i++)
32 cout << tmp[i] << " , ";
33 cout << endl;
34 ofstream fout("debug.out");
35 for (int i=0; i<BUFSIZE; i++)
36 fout << buf[i][0] << " " << buf[i][1] << endl;
37 fout.close();
38 ofstream gen_out("gen.out");
39 gen_out << gen;
40 gen_out.close();
41 exit(1);
42 }
43 n++;
44 }
45
46 return 0;
47}
48