Check in code for new random number generator

This commit is contained in:
2022-03-31 17:15:15 -04:00
parent 7fc6263e37
commit c48e02642a
9 changed files with 291 additions and 8 deletions

View File

@@ -0,0 +1,43 @@
#include <iostream>
#include <cstdint>
bool storable(int64_t n) {
double d = n;
int64_t n1 = int64_t(d);
return n1 == n;
}
// Find the biggest number where the number is storable,
// and all numbers smaller are also storable.
int64_t find_biggest() {
int64_t v = 256;
int64_t best = 256;
while (true) {
for (int i = 0; i < 100; i++) {
if (!storable(v - i)) {
return best;
}
}
best = v;
v <<= 1;
}
}
int main(int argc, char **argv) {
int64_t best = find_biggest();
printf("%016lx ", best);
for (int i = -12; i <= 12; i++) {
if (i == 0) printf(" ");
if (storable(best + i)) {
printf("* ");
} else {
printf("- ");
}
if (i == 0) printf(" ");
}
printf("\n");
return 0;
}