Last active
September 25, 2019 19:08
-
-
Save BillyDonahue/53fa229d311cc6ac1f5ab21bd588e11f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+/** | |
+ * Test uniformity of nextInt32(max) | |
+ */ | |
+TEST(RandomTest, NextInt32Uniformity) { | |
+ PseudoRandom prng(10); | |
+ /* Break the range into sections. */ | |
+ /* Check that all sections get roughly equal # of hits */ | |
+ constexpr int32_t kMax = (int32_t{3} << 29) - 1; | |
+ constexpr size_t kBuckets = 64; | |
+ constexpr size_t kNIter = 1'000'000; | |
+ std::vector<size_t> hist(kBuckets); | |
+ for (size_t i = 0; i < kNIter; ++i) { | |
+ auto next = prng.nextInt32(kMax); | |
+ ASSERT_GTE(next, 0); | |
+ ASSERT_LTE(next, kMax); | |
+ ++hist[double(next) * kBuckets / (kMax+1)]; | |
+ } | |
+ if (1) { // super verbose | |
+ for (size_t i = 0; i < hist.size(); ++i) { | |
+ std::string stars(hist[i]/256, '*'); | |
+ unittest::log() << format(FMT_STRING(" [{:4}] {:4} : {}"), | |
+ i, hist[i], stars); | |
+ } | |
+ } | |
+ constexpr double mu = kNIter / kBuckets; | |
+ constexpr double muSqInv = 1. / (mu * mu); | |
+ for (size_t i = 0; i < hist.size(); ++i) { | |
+ double dev = std::sqrt(std::pow(hist[i] - mu, 2) * muSqInv); | |
+ std::string stars(hist[i]/256, '*'); | |
+ ASSERT_LT(dev, 0.1) << format(FMT_STRING("hist[{}]={}, mu={}"), i, hist[i], mu); | |
+ } | |
+} | |
+ | |
2019-09-25T13:33:56.672-0400 I - [main] going to run test: NextInt32Uniformity | |
2019-09-25T13:33:56.916-0400 I - [main] [ 0] 17624 : ******************************************************************** | |
2019-09-25T13:33:56.917-0400 I - [main] [ 1] 17506 : ******************************************************************** | |
2019-09-25T13:33:56.917-0400 I - [main] [ 2] 17522 : ******************************************************************** | |
2019-09-25T13:33:56.918-0400 I - [main] [ 3] 17653 : ******************************************************************** | |
2019-09-25T13:33:56.918-0400 I - [main] [ 4] 17529 : ******************************************************************** | |
2019-09-25T13:33:56.919-0400 I - [main] [ 5] 17475 : ******************************************************************** | |
2019-09-25T13:33:56.920-0400 I - [main] [ 6] 17634 : ******************************************************************** | |
2019-09-25T13:33:56.920-0400 I - [main] [ 7] 17330 : ******************************************************************* | |
2019-09-25T13:33:56.921-0400 I - [main] [ 8] 17560 : ******************************************************************** | |
2019-09-25T13:33:56.921-0400 I - [main] [ 9] 17377 : ******************************************************************* | |
2019-09-25T13:33:56.922-0400 I - [main] [ 10] 17731 : ********************************************************************* | |
2019-09-25T13:33:56.922-0400 I - [main] [ 11] 17576 : ******************************************************************** | |
2019-09-25T13:33:56.923-0400 I - [main] [ 12] 17457 : ******************************************************************** | |
2019-09-25T13:33:56.924-0400 I - [main] [ 13] 17600 : ******************************************************************** | |
2019-09-25T13:33:56.924-0400 I - [main] [ 14] 17734 : ********************************************************************* | |
2019-09-25T13:33:56.925-0400 I - [main] [ 15] 17701 : ********************************************************************* | |
2019-09-25T13:33:56.925-0400 I - [main] [ 16] 17840 : ********************************************************************* | |
2019-09-25T13:33:56.926-0400 I - [main] [ 17] 17325 : ******************************************************************* | |
2019-09-25T13:33:56.926-0400 I - [main] [ 18] 17549 : ******************************************************************** | |
2019-09-25T13:33:56.927-0400 I - [main] [ 19] 17434 : ******************************************************************** | |
2019-09-25T13:33:56.928-0400 I - [main] [ 20] 17661 : ******************************************************************** | |
2019-09-25T13:33:56.928-0400 I - [main] [ 21] 17593 : ******************************************************************** | |
2019-09-25T13:33:56.929-0400 I - [main] [ 22] 17833 : ********************************************************************* | |
2019-09-25T13:33:56.929-0400 I - [main] [ 23] 17661 : ******************************************************************** | |
2019-09-25T13:33:56.930-0400 I - [main] [ 24] 17563 : ******************************************************************** | |
2019-09-25T13:33:56.930-0400 I - [main] [ 25] 17534 : ******************************************************************** | |
2019-09-25T13:33:56.931-0400 I - [main] [ 26] 17466 : ******************************************************************** | |
2019-09-25T13:33:56.932-0400 I - [main] [ 27] 17527 : ******************************************************************** | |
2019-09-25T13:33:56.932-0400 I - [main] [ 28] 17425 : ******************************************************************** | |
2019-09-25T13:33:56.933-0400 I - [main] [ 29] 17540 : ******************************************************************** | |
2019-09-25T13:33:56.933-0400 I - [main] [ 30] 17513 : ******************************************************************** | |
2019-09-25T13:33:56.934-0400 I - [main] [ 31] 17510 : ******************************************************************** | |
2019-09-25T13:33:56.934-0400 I - [main] [ 32] 17366 : ******************************************************************* | |
2019-09-25T13:33:56.935-0400 I - [main] [ 33] 17541 : ******************************************************************** | |
2019-09-25T13:33:56.936-0400 I - [main] [ 34] 17811 : ********************************************************************* | |
2019-09-25T13:33:56.936-0400 I - [main] [ 35] 17468 : ******************************************************************** | |
2019-09-25T13:33:56.937-0400 I - [main] [ 36] 17605 : ******************************************************************** | |
2019-09-25T13:33:56.937-0400 I - [main] [ 37] 17708 : ********************************************************************* | |
2019-09-25T13:33:56.938-0400 I - [main] [ 38] 17526 : ******************************************************************** | |
2019-09-25T13:33:56.938-0400 I - [main] [ 39] 17750 : ********************************************************************* | |
2019-09-25T13:33:56.939-0400 I - [main] [ 40] 17486 : ******************************************************************** | |
2019-09-25T13:33:56.940-0400 I - [main] [ 41] 17370 : ******************************************************************* | |
2019-09-25T13:33:56.940-0400 I - [main] [ 42] 15652 : ************************************************************* | |
2019-09-25T13:33:56.941-0400 I - [main] [ 43] 11732 : ********************************************* | |
2019-09-25T13:33:56.941-0400 I - [main] [ 44] 11793 : ********************************************** | |
2019-09-25T13:33:56.942-0400 I - [main] [ 45] 11935 : ********************************************** | |
2019-09-25T13:33:56.942-0400 I - [main] [ 46] 11806 : ********************************************** | |
2019-09-25T13:33:56.943-0400 I - [main] [ 47] 11740 : ********************************************* | |
2019-09-25T13:33:56.944-0400 I - [main] [ 48] 11664 : ********************************************* | |
2019-09-25T13:33:56.944-0400 I - [main] [ 49] 11770 : ********************************************* | |
2019-09-25T13:33:56.945-0400 I - [main] [ 50] 11659 : ********************************************* | |
2019-09-25T13:33:56.945-0400 I - [main] [ 51] 11736 : ********************************************* | |
2019-09-25T13:33:56.946-0400 I - [main] [ 52] 11705 : ********************************************* | |
2019-09-25T13:33:56.946-0400 I - [main] [ 53] 11594 : ********************************************* | |
2019-09-25T13:33:56.947-0400 I - [main] [ 54] 11771 : ********************************************* | |
2019-09-25T13:33:56.948-0400 I - [main] [ 55] 11467 : ******************************************** | |
2019-09-25T13:33:56.948-0400 I - [main] [ 56] 11646 : ********************************************* | |
2019-09-25T13:33:56.949-0400 I - [main] [ 57] 11691 : ********************************************* | |
2019-09-25T13:33:56.949-0400 I - [main] [ 58] 11860 : ********************************************** | |
2019-09-25T13:33:56.950-0400 I - [main] [ 59] 11768 : ********************************************* | |
2019-09-25T13:33:56.950-0400 I - [main] [ 60] 11889 : ********************************************** | |
2019-09-25T13:33:56.951-0400 I - [main] [ 61] 11698 : ********************************************* | |
2019-09-25T13:33:56.951-0400 I - [main] [ 62] 11811 : ********************************************** | |
2019-09-25T13:33:56.952-0400 I - [main] [ 63] 11999 : ********************************************** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Catchpoint 5 (call to syscall read), 0x00007ffff4e0534e in __libc_read (fd=6, buf=buf@entry=0x7fffeee07820, nbytes=nbytes@entry=8191) at ../sysdeps/unix/sysv/linux/read.c:27 | |
27 ../sysdeps/unix/sysv/linux/read.c: No such file or directory. | |
(gdb) bt | |
#0 0x00007ffff4e0534e in __libc_read (fd=6, buf=buf@entry=0x7fffeee07820, nbytes=nbytes@entry=8191) at ../sysdeps/unix/sysv/linux/read.c:27 | |
#1 0x00007ffff7916287 in std::__basic_file<char>::xsgetn (this=this@entry=0x7fffeee004d8, __s=0x7fffeee07820 '\253' <repeats 200 times>..., __n=__n@entry=8191) at basic_file.cc:285 | |
#2 0x00007ffff793ff30 in std::basic_filebuf<char, std::char_traits<char> >::underflow (this=0x7fffeee00470) at /home/billy/dev/10gen/toolchain-builder/tmp/build-gcc-v3.sh-sRY/build/x86_64-mongodb-linux/libstdc++-v3/include/bits/char_traits.h:350 | |
#3 0x00007ffff78ee576 in std::basic_streambuf<char, std::char_traits<char> >::uflow (this=0x7fffeee00470) at /home/billy/dev/10gen/toolchain-builder/tmp/build-gcc-v3.sh-sRY/build/x86_64-mongodb-linux/libstdc++-v3/include/streambuf:707 | |
#4 std::basic_streambuf<char, std::char_traits<char> >::xsgetn (this=this@entry=0x7fffeee00470, __s=__s@entry=0x7fffffffd468 " \362\333\356\377\177", __n=__n@entry=8) | |
at /home/billy/dev/10gen/toolchain-builder/tmp/build-gcc-v3.sh-sRY/build/x86_64-mongodb-linux/libstdc++-v3/include/bits/streambuf.tcc:64 | |
#5 0x00007ffff79409e3 in std::basic_filebuf<char, std::char_traits<char> >::xsgetn (this=0x7fffeee00470, __s=0x7fffffffd468 " \362\333\356\377\177", __n=8) | |
at /home/billy/dev/10gen/toolchain-builder/tmp/build-gcc-v3.sh-sRY/build/x86_64-mongodb-linux/libstdc++-v3/include/bits/codecvt.h:210 | |
#6 0x00007ffff78e989d in std::basic_streambuf<char, std::char_traits<char> >::sgetn (__n=8, __s=0x7fffffffd468 " \362\333\356\377\177", this=<optimized out>) | |
at /home/billy/dev/10gen/toolchain-builder/tmp/build-gcc-v3.sh-sRY/build/x86_64-mongodb-linux/libstdc++-v3/include/streambuf:364 | |
#7 std::istream::read (this=0x7fffeee00460, __s=0x7fffffffd468 " \362\333\356\377\177", __n=8) at /home/billy/dev/10gen/toolchain-builder/tmp/build-gcc-v3.sh-sRY/build/x86_64-mongodb-linux/libstdc++-v3/include/bits/istream.tcc:667 | |
#8 0x00007ffff7c9b2be in mongo::random_detail::SecureUrbg::State::operator() (this=0x7fffeee00460) at src/mongo/platform/random.cpp:127 | |
#9 0x00007ffff7c9b02c in mongo::random_detail::SecureUrbg::operator() (this=0x7fffeedbf220) at src/mongo/platform/random.cpp:139 | |
#10 0x00005555557397ee in std::uniform_int_distribution<long>::operator()<mongo::random_detail::SecureUrbg> (this=0x7fffffffd5f0, __urng=..., __param=...) at /opt/mongodbtoolchain/stow/gcc-v3.sFn/include/c++/8.2.0/bits/uniform_int_dist.h:275 | |
#11 0x0000555555736bd3 in std::uniform_int_distribution<long>::operator()<mongo::random_detail::SecureUrbg> (this=0x7fffffffd5f0, __urng=...) at /opt/mongodbtoolchain/stow/gcc-v3.sFn/include/c++/8.2.0/bits/uniform_int_dist.h:166 | |
#12 0x0000555555733f35 in mongo::RandomBase<mongo::random_detail::SecureUrbg>::_nextAny<long> (this=0x7fffeedbf220) at src/mongo/platform/random.h:137 | |
#13 0x000055555572f578 in mongo::RandomBase<mongo::random_detail::SecureUrbg>::nextInt64 (this=0x7fffeedbf220) at src/mongo/platform/random.h:120 | |
#14 0x00007ffff7c7d232 in mongo::_mongoInitializerFunction_OIDGeneration (context=0x7fffffffd7b0) at src/mongo/bson/oid.cpp:58 | |
#15 0x00007ffff7f9935b in std::_Function_handler<mongo::Status (mongo::InitializerContext*), mongo::Status (*)(mongo::InitializerContext*)>::_M_invoke(std::_Any_data const&, mongo::InitializerContext*&&) (__functor=..., __args#0=@0x7fffffffd6f8: 0x7fffffffd7b0) | |
at /opt/mongodbtoolchain/stow/gcc-v3.sFn/include/c++/8.2.0/bits/std_function.h:283 | |
#16 0x00007ffff7c28598 in std::function<mongo::Status (mongo::InitializerContext*)>::operator()(mongo::InitializerContext*) const (this=0x7fffeede5400, __args#0=0x7fffffffd7b0) at /opt/mongodbtoolchain/stow/gcc-v3.sFn/include/c++/8.2.0/bits/std_function.h:687 | |
#17 0x00007ffff7c27481 in mongo::Initializer::executeInitializers (this=0x7ffff7dbb6e0 <mongo::getGlobalInitializer()::theGlobalInitializer>, args=..., env=...) at src/mongo/base/initializer.cpp:71 | |
#18 0x00007ffff7c278ee in mongo::runGlobalInitializers (args=..., env=...) at src/mongo/base/initializer.cpp:114 | |
#19 0x00007ffff7c27b26 in mongo::runGlobalInitializers (argc=3, argv=0x7fffffffddb8, envp=0x7fffffffdee0) at src/mongo/base/initializer.cpp:133 | |
#20 0x00007ffff7c27c8b in mongo::runGlobalInitializersOrDie (argc=3, argv=0x7fffffffddb8, envp=0x7fffffffddd8) at src/mongo/base/initializer.cpp:141 | |
#21 0x00007ffff7fe51f3 in main (argc=3, argv=0x7fffffffddb8, envp=0x7fffffffddd8) at src/mongo/unittest/unittest_main.cpp:52 | |
#22 0x00007ffff4a24b97 in __libc_start_main (main=0x7ffff7fe519c <main(int, char**, char**)>, argc=3, argv=0x7fffffffddb8, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffdda8) at ../csu/libc-start.c:310 | |
#23 0x00005555556f9cea in _start () | |
(gdb) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment