29 std::cout <<
"Using " << r.Name() <<
"\n"
30 <<
"with seed " << r.SeedString() <<
"\n";
32 std::cout <<
"Estimate pi = ";
33 size_t in = 0, num = 10000;
34 for (
size_t i = 0; i < num; ++i) {
37 if (x * x + y * y < 0.25) ++in;
39 std::cout << (4.0 * in) / num <<
"\n";
42 std::cout <<
"Tossing a coin 20 times: ";
43 for (
size_t i = 0; i < 20; ++i) std::cout << (r.
Boolean() ?
"H" :
"T");
46 std::cout <<
"Generate 20 random bits: " << r.
Bits<20>() <<
"\n";
48 std::cout <<
"Throwing a pair of dice 15 times:";
49 for (
size_t i = 0; i < 15; ++i)
55 unsigned w[] = { 0, 0, 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1 };
58 std::cout <<
"A different way of throwing dice:";
59 for (
size_t i = 0; i < 15; ++i) std::cout <<
" " << sel(r);
63 std::cout <<
"Draw balls from urn containing 5 red and 5 white balls: ";
65 while (t) std::cout << (r.
Prob(w, t--) ? w--,
"W" :
"R");
69 std::cout <<
"Shuffling the letters a..z: ";
70 std::string digits =
"abcdefghijklmnopqrstuvwxyz";
71 std::random_shuffle(digits.begin(), digits.end(), r);
72 std::cout << digits <<
"\n";
75 std::cout <<
"Estimate mean and variance of normal distribution: ";
80 double x = n(r), m1 = m + (x - m)/++k;
81 s += (x - m) * (x - m1); m = m1;
83 std::cout << m <<
", " << s/(k - 1) <<
"\n";
88 std::cout <<
"Some low precision reals (1/" << (1<<prec) <<
"):";
89 for (
size_t i = 0; i < 5; ++i) std::cout <<
" " << r.
Fixed<real, prec>();
92 std::cout <<
"Used " << r.Count() <<
" random numbers\n";
95 RandomLib::MRandom32::SelfTest();
96 std::cout <<
"Self test of " << RandomLib::MRandom32::Name()
98 RandomLib::MRandom64::SelfTest();
99 std::cout <<
"Self test of " << RandomLib::MRandom64::Name()
101 RandomLib::SRandom32::SelfTest();
102 std::cout <<
"Self test of " << RandomLib::SRandom32::Name()
104 RandomLib::SRandom64::SelfTest();
105 std::cout <<
"Self test of " << RandomLib::SRandom64::Name()
108 catch (std::out_of_range& e) {
109 std::cerr <<
"Self test FAILED: " << e.what() <<
"\n";
Header for NormalDistribution.
Generate random integers, reals, and booleans.
Random selection from a discrete set.
Header for Random, RandomGenerator.
IntType IntegerC(IntType n)
std::bitset< nbits > Bits()