Advertisement
Kyrexar

Rand test

May 1st, 2013
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.62 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. #define D 6
  6. #define N 100000000
  7.  
  8. int main(){
  9.     int dado[D+1], i;
  10.     clock_t ti, tf;
  11.     double dif;
  12.     srand(time(NULL));
  13.    
  14.     ti=clock();
  15.    
  16.     for( i=1 ; i<D+1 ; i++ )
  17.          dado[i]=0;
  18.    
  19.     for( i=0 ; i<N ; i++ )
  20.          dado[rand()%D+1]++;
  21.    
  22.     for( i=1 ; i<D+1 ; i++ )
  23.          printf(" %d esta repetido %d veces \n",i,dado[i]);
  24.    
  25.     tf=clock();
  26.    
  27.     dif = ((double)tf - (double) ti) / CLOCKS_PER_SEC;
  28.     printf(" %d numeros pseudoaleatorios en %f segundos \n ",N,dif);
  29.    
  30.     system("PAUSE");
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement