Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <thread>
- #include <atomic>
- #include <chrono>
- std::atomic<long> A, B, C;
- int popcount(__uint128_t x) {
- return __builtin_popcountll(x>>64) + __builtin_popcountll(x);
- }
- void f() {
- FILE* fp = fopen("/dev/urandom", "rb");
- __uint128_t r = 0;
- const __uint128_t MASK = ((__uint128_t)1<<100)-1;
- while (1) {
- fread(&r, 13, 1, fp);
- int a = popcount(r & r>>1 & MASK);
- int b = popcount(~r & ~r>>2 & MASK);
- //printf ("%d %d %016llX %016llX", a,b, r); exit(0);
- ++C; A+=a>b; B+=b>a;
- }
- }
- int main() {
- for (int i=0; i<1; ++i) {
- std::thread(f).detach();
- }
- puts(" Tries "
- " Alice "
- " Bob");
- while (1) {
- using namespace std::chrono;
- std::this_thread::sleep_for(1s);
- printf("%16ld%16ld%16ld%16f%16f\n",
- (long)C, (long)A, (long)B, A/(double)C, B/(double)C);
- }
- }
- /*
- /tmp$clang++ -O2 -march=native ace.cpp && ./a.out
- Tries Alice Bob
- 16094129 7754735 7735217 0.481836 0.480624
- 32559419 15687511 15648598 0.481812 0.480617
- 49981597 24078565 24025584 0.481749 0.480689
- 67558478 32544818 32475877 0.481728 0.480708
- 84934340 40916597 40826653 0.481744 0.480685
- 102541469 49401059 49288415 0.481767 0.480668
- 120146039 57881533 57750303 0.481760 0.480668
- 137669395 66320196 66176514 0.481735 0.480692
- 155200340 74764887 74603746 0.481731 0.480693
- 172655724 83174404 82993198 0.481736 0.480686
- 190123706 91588181 91390641 0.481729 0.480690
- 207559197 99986660 99772391 0.481726 0.480694
- 225032664 108405140 108168940 0.481731 0.480681
- 242568649 116851786 116600393 0.481727 0.480690
- 260095684 125293907 125027412 0.481722 0.480698
- 277674456 133760597 133478529 0.481717 0.480702
- 295167942 142187855 141888559 0.481718 0.480705
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement