#include <iostream>
#include <cstdlib>
#include <chrono>      //for chrono::system_clock
#include <random>      //for default_random_engine
#include <functional>  //for bind
using namespace std;

int main()
{
	int n {10};    //Generate random ints in the range 0 to n-1 inclusive.

	//The expression r() will be a random int in range 0 to n-1 inclusive.
	unsigned seed = chrono::system_clock::now().time_since_epoch().count();
	default_random_engine engine {seed};
	uniform_int_distribution<int> distribution {0, n - 1};
	auto r {bind(distribution, engine)};

	int a[n] {};   //initialized to n zeros: {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

	//Generate 500 random ints.
	for (int i {0}; i < 500; ++i) {
		int x {r()};   //a random int in the range 0 to n-1 inclusive
		++a[x];        //Tally how many times this value was generated.
	}

	//Output a picture of the contents of the array.
	for (int i {0}; i < n; ++i) {
		cout << i << "   ";

		//Output a line of a[i] asterisks.
		for (int j {0}; j < a[i]; ++j) {
			cout << "*";
		}
		cout << "\n";
	}

	return EXIT_SUCCESS;
}