myHistogram = boost/Random + map

The project is compile but something wrong in switch case loop. The amount of numbers counting uncorrect. Please take a look to print screen. What I did wrong . Many thanks in advance.

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
//

#include <boost/random.hpp> // Convenience header file
#include <iostream>
#include <ctime>			// std::time
#include <boost/Random/detail/const_mod.hpp> // LCG class
#include <map>

using namespace std;

template<class PRNG, class Dist>
inline boost::variate_generator<PRNG&, Dist> make_gen(PRNG & rng, Dist d)
{
  return boost::variate_generator<PRNG&, Dist>(rng, d);
}

int main()
{
	
	// Get random number generator
	boost::mt19937 rng;
	// Set the seed. 
	rng.seed(static_cast<boost::uint32_t> (std::time(0)));
	boost::random::uniform_int_distribution<int> six(1,6);
	rng.seed(static_cast<unsigned int> (std::time(0)));
	boost::variate_generator<boost::mt19937&, boost::random::uniform_int_distribution<int> > 
							uniRng(rng, six);

	map<int, long> myHistogram;

	myHistogram[1] = 0; 
	myHistogram[2] = 0;
	myHistogram[3] = 0;
	myHistogram[4] = 0;
	myHistogram[5] = 0;
	myHistogram[6] = 0;

	for (int n = 0; n <5; ++n)
	{
		 switch (uniRng())
		 {
		case 1: myHistogram[1]++; break;
		case 2: myHistogram[2]++; break;
		case 3: myHistogram[3]++; break;
		case 4: myHistogram[4]++; break;
		case 5: myHistogram[5]++; break;
		default: myHistogram[6]++; break;
		 }
		 cout << uniRng() << endl;
	}
			for (auto i = myHistogram.cbegin(); i != myHistogram.cend(); ++i)
			{
				cout <<"case:" << i->first << " frequency: " <<i->second<<" "<< endl;
			}
	

	return 0;

}
The amount of numbers counting uncorrect.
What does that mean?

On line 25: why do you seed it twice?

On line 38: Are you aware that you feed myHistogram with just 5 values?
Topic archived. No new replies allowed.