Skip to content
Snippets Groups Projects
test_random.cpp 774 B
Newer Older
#include <iostream>
#include <vector>

#include "random_int.h"
#include "grandom.h"


template <typename Vec> void print_ascii(const Vec & v, std::ostream &o=std::cout){
	for(int i=0; i!=v.size(); ++i) {
		std::cout << i << '\t';
		for(int j=0; j!=v[i]; ++j) std::cout << '*';
		std::cout << std::endl;
	}

}

int main(){
	rand_int rnd{0,4};
	std::vector<int> histo(5);
	for(int i=0;i!=200;++i) ++histo[rnd()];

	std::cout << "The uniform distribution \n\n";
	print_ascii(histo);

	grand grnd{15.,4.};
	std::vector<int> ghisto(30);
	for(int i=0,j=0;i!=500;++i, j=grnd()) if(j<ghisto.size())++ghisto[j]; else std::cout <<"Ooooppsss, out of range :" << j << '\n';
	std::cout << "The normal distribution \n\n";
	print_ascii(ghisto);
	return 0;
}