30 template<
typename NumType,
int nbins=10,
int nstars = 100,
int ntries=100000>
33 for (
int count=0; count<ntries; ++count) {
38 ++hist[(
int)(0.5+num)];
41 int bar = (hist[
bin]*nstars)/ntries;
44 char sbin =
'0'+(
bin-1);
58 auto rnd = Factory::lookup<IRandom>(gen_random_name);
59 auto rndcfg = Factory::lookup<IConfigurable>(gen_random_name);
62 auto cfg = rndcfg->default_configuration();
63 cfg[
"generator"] = generator_name;
64 rndcfg->configure(
cfg);
74 cout <<
"binomial(9,0.5)\n";
75 histify<int>(std::bind(&IRandom::binomial, ptr, 9, 0.5));
77 cout <<
"normal(5.0,3.0)\n";
78 histify<double>(std::bind(&IRandom::normal, ptr, 5.0,3.0));
80 cout <<
"uniform(0.0,10.0)\n";
81 histify<double>(std::bind(&IRandom::uniform, ptr, 0.0, 10.0));
82 cout <<
"uniform(2.0,5.0)\n";
83 histify<double>(std::bind(&IRandom::uniform, ptr, 2.0,5.0));
85 cout <<
"range(0,10)\n";
86 histify<int>(std::bind(&IRandom::range, rnd, 0,10));
87 cout <<
"range(2,4)\n";
88 histify<int>(std::bind(&IRandom::range, rnd, 2,4));
93 auto rnd = Factory::lookup<IRandom>(
"Random");
96 std::vector<double> v1(ntries), v2(ntries);
97 for (
int ind=0; ind<ntries; ++ind) {
98 v1[ind] = rnd->normal(0,1);
100 for (
int ind=0; ind<ntries; ++ind) {
101 v2[ind] = rnd->normal(0,1);
103 for (
size_t ind=0; ind<v1.size(); ++ind) {
104 cerr << v1[ind] <<
"\t" << v2[ind] <<
endl;
114 pm.
add(
"WireCellGen");
117 cout <<
"DEFAULT:\n";
119 em(
"default generator");
121 cout <<
"\nTWISTER:\n";
123 em(
"twister generator");
125 cout <<
"\nBOGUS:\n";
127 em(
"bogus generator");
void histify(std::function< NumType()> gen)
const std::string instance
void test_named(std::string generator_name)
double normalize(std::complex< double > val)
QTextStream & bin(QTextStream &s)
Plugin * add(const std::string &plugin_name, const std::string &libname="")
Add a plugin. If libname is not given, try to derive it.
void function(int client, int *resource, int parblock, int *test, int p)
std::string summary() const
Return summary up to now.
QTextStream & endl(QTextStream &s)