Turecko-americká vycházející matematická hvězda Levent Alpöge ze společnosti Anthropic vyvolal pozdvižení oznámením (PDF), že s pomocí superinteligence Claude od Antropicu dokázal vyřešit jeden ze sedmi největších matematických problémů tisíciletí, slavnou Riemannovu hypotézu (prvočísla se mezi čísly objevují zdánlivě nepravidelně, hypotéza tvrdí, že za jejich rozmístěním je určitý řád). Svůj důkaz uvolnil jako open-source
… více »#include <iostream>
#include <stdlib.h>
#include <stdint.h>
#include <time.h>
#include <iomanip>
int main()
{
srand(time(NULL));
std::cout << " RAND_MAX: " << RAND_MAX << std::endl;
uint32_t r = rand() % 2147483648;
r += rand() % 2147483648;
std::cout << " 31bit: "<< std::setw(10) << std::hex << r << std::endl;
r = ((rand() % 256) << 24) | ((rand() % 256) << 16) | ((rand() % 256) << 8) | ((rand() % 256)) ;
std::cout << " 8bit: " << std::setw(10) << std::hex<< r << std::endl;
return 0;
}
#include <iostream>
#include <stdlib.h>
#include <stdint.h>
#include <time.h>
#include <iomanip>
int main()
{
int cnt[256] = {0, };
for (int i = 0; i < 100000; ++i)
{
uint32_t r = rand() % 128;
r += rand() % 128;
++cnt[r];
}
for (int i = 0; i < 256; ++i)
{
std::cout << cnt[i] << "\n";
}
}
a dava to distribuci co je v priloze.
Ten druhej zpusob je lepsi, nekde jsem ale cetl ze u "linear congruential generatoru" (kterej je predpokladam pouzitej v rand()) maji spodni bity kratsi periodu nez horni, proto by mozna bylo lepsi pouzit deleni misto modula.
Puvodnimu autorovy bych doporucil:
- pokud potrebujes "cryptographically secure" generator tak pouzi /dev/random
- pokud ne tak se podivej na generatory v c++11
- pokud nemuzes pouzit c++11 tak naprogramuj vlastni linear congruential generator. Navod treba tady: http://en.wikipedia.org/wiki/Linear_congruential_generator. Z tabulky vem hodnoty pro 64 bit. Celkove to budou asi 3 radky kodu...
Tiskni
Sdílej: