/* 31 Jan 2003 -- Sam Hocevar */ #define TRIES 100000 /* On va pas y passer la nuit non plus ! */ #define X 59 int trial(void) { int tirage[256]; int zeros, others, mostfreq, freq; int i,j,k; zeros=0; others=0; /* Init */ for( i = 0; i < 255 ; i++ ) { tirage[i] = 0; } /* Tirage */ for( i = 0; i < X ; i++ ) { if( (unsigned int)random() % 100 < 5 ) { /* 5% */ tirage[0]++; } else { /* (95/255)% chacun */ tirage[1+((unsigned int)random()%255)]++; } } /* Faites pas chier avec mon code */ mostfreq = -1; freq = -1; for( i = 0; i < 255 ; i++ ) { if( tirage[i] >= freq ) { freq = tirage[i]; mostfreq = i; } } /* 0 est tombé le plus fréquemment */ if( mostfreq == 0 ) { return 0; } /* Au moins deux ex aequo */ if( tirage[mostfreq] == tirage[0] ) { return 1; } /* Le plus fréquent n'est pas 0 */ return 2; } int main(void) { int i, success = 0, exaequo = 0; srandom(time()); for( i = 0; i < TRIES; i++ ) { switch( trial() ) { case 0: success++; break; case 1: exaequo++; break; } } printf("0 tombe %i fois premier, %i fois exaequo (sur %i)\n", success, exaequo, TRIES); return 0; }