32 std::cout <<
"Using " << r.Name() <<
"\n"
33 <<
"with seed " << r.SeedString() <<
"\n\n";
36 <<
"Sampling exactly from the normal distribution. First number is\n"
37 <<
"in binary with ... indicating an infinite sequence of random\n"
38 <<
"bits. Second number gives the corresponding interval. Third\n"
39 <<
"number is the result of filling in the missing bits and rounding\n"
40 <<
"exactly to the nearest representable double.\n";
43 long long num = 20000000ll;
44 long long bitcount = 0;
46 for (
long long i = 0; i < num; ++i) {
47 long long k = r.Count();
49 bitcount += r.Count() - k;
51 std::pair<double, double> z = x.
Range();
52 std::cout << x <<
" = "
53 <<
"(" << z.first <<
"," << z.second <<
")";
54 double v = x.
Value<
double>(r);
55 std::cout <<
" = " << v <<
"\n";
56 }
else if (i == numprint)
57 std::cout << std::flush;
60 <<
"Number of bits needed to obtain the binary representation averaged\n"
61 <<
"over " << num <<
" samples = " << bitcount/double(num) <<
"\n\n";
65 <<
"Sampling exactly from exp(-x). First number is in binary with\n"
66 <<
"... indicating an infinite sequence of random bits. Second\n"
67 <<
"number gives the corresponding interval. Third number is the\n"
68 <<
"result of filling in the missing bits and rounding exactly to\n"
69 <<
"the nearest representable double.\n";
72 long long num = 50000000ll;
73 long long bitcount = 0;
75 for (
long long i = 0; i < num; ++i) {
76 long long k = r.Count();
78 bitcount += r.Count() - k;
80 std::pair<double, double> z = x.
Range();
81 std::cout << x <<
" = "
82 <<
"(" << z.first <<
"," << z.second <<
")";
83 double v = x.
Value<
double>(r);
84 std::cout <<
" = " << v <<
"\n";
85 }
else if (i == numprint)
86 std::cout << std::flush;
89 <<
"Number of bits needed to obtain the binary representation averaged\n"
90 <<
"over " << num <<
" samples = " << bitcount/double(num) <<
"\n\n";
94 <<
"Sampling exactly from the discrete normal distribution with\n"
95 <<
"sigma = 7 and mu = 1/2.\n";
97 long long num = 50000000ll;
98 long long count = r.Count();
100 for (
long long i = 0; i < num; ++i) {
103 std::cout << k <<
" ";
104 else if (i == numprint)
105 std::cout << std::endl;
107 count = r.Count() - count;
109 <<
"Number of random variates needed averaged\n"
110 <<
"over " << num <<
" samples = " << count/double(num) <<
"\n\n";
114 <<
"Sampling exactly from the discrete normal distribution with\n"
115 <<
"sigma = 1024 and mu = 1/7. First result printed is a uniform\n"
116 <<
"range (with covers a power of two). The second number is the\n"
117 <<
"result of sampling additional bits within that range to obtain\n"
118 <<
"a definite result.\n";
120 long long num = 20000000ll;
121 long long count = r.Count();
122 long long entropy = 0;
124 for (
long long i = 0; i < num; ++i) {
128 std::cout << u <<
" = ";
131 std::cout << k <<
"\n";
132 else if (i == numprint)
133 std::cout << std::flush;
135 count = r.Count() - count;
137 <<
"Number of random bits needed for full result (for range) averaged\n"
138 <<
"over " << num <<
" samples = " << count/double(num) <<
" ("
139 << (count - entropy)/
double(num) <<
")\n\n";
143 <<
"Random bits with 1 occurring with probability 1/pi exactly:\n";
144 long long num = 100000000ll;
148 long long k = r.Count();
149 for (
long long i = 0; i < num; ++i) {
152 if (i < numprint) std::cout << int(b);
153 else if (i == numprint) std::cout <<
"..." << std::flush;
156 std::cout <<
"Frequency of 1 averaged over " << num <<
" samples = 1/"
157 << double(num)/nbits <<
"\n"
158 <<
"bits/sample = " << (r.Count() - k)/
double(num) <<
"\n\n";
162 <<
"Random bits with 1 occurring with probability 1/e exactly:\n";
163 long long num = 200000000ll;
167 long long k = r.Count();
168 for (
long long i = 0; i < num; ++i) {
171 if (i < numprint) std::cout << int(b);
172 else if (i == numprint) std::cout <<
"..." << std::flush;
175 std::cout <<
"Frequency of 1 averaged over " << num <<
" samples = 1/"
176 << double(num)/nbits <<
"\n"
177 <<
"bits/sample = " << (r.Count() - k)/
double(num) <<
"\n";
Return true with probability 1/e = exp(−1).
Generate random integers, reals, and booleans.
Infinite precision random numbers.
Header for Random, RandomGenerator.
std::pair< double, double > Range() const
The discrete normal distribution (alternate version).
Header for DiscreteNormal.
Header for ExactExponential.
RealType Value(Random &r)
The discrete normal distribution.
Sample exactly from an exponential distribution.
Header for InversePiProb.
Sample exactly from a normal distribution.
Header for DiscreteNormalAlt.
Return true with probability 1/π.