Sono riuscito a scrivere un programmino che genere una serie di numeri l più casuali possibili, cercando pezzi di codice in rete
Potreste spiegarmi cosa fanno esattamente struct timeval t1 e gettimeofday(&t1, NULL)?codice:#include <iostream> #include <sys/time.h> #include <cstdlib> #include <random> int rnd(int low, int high) { struct timeval t1; gettimeofday(&t1, NULL); minstd_rand eng(t1.tv_usec * t1.tv_sec); // seed the generator uniform_int_distribution<> distr(low, high); // define the range return distr(eng); // generate numbers } int main() { for(int n=0; n<40; ++n) std::cout << rnd(1, 100) << ' '; // generate numbers system("PAUSE"); }
Sono alle prime armi, quindi non date troppe cose per scontate![]()

Rispondi quotando