john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

random integer distribution

/* 03dec04 john pfeiffer, an array of the distribution of random integers */
#include <stdio.h>
#include <stdlib.h>     
#include <time.h>       
/* stdlib.h is for srand & rand */
int main(int argc, char* argv[])
{
    int i=0, 
        j=0, 
        ARnum[6] = {0,0,0,0,0,0};

    srand( time(0) );

    for(j=0; j<10; j++)
    {
       for(i=0; i<10000; i++)
       {
        switch( rand()%6 )
          {
            case 0:
                    ARnum[0]++;
                break;
            case 1:
                    ARnum[1]++;
                break;
            case 2:
                    ARnum[2]++;
                break;
            case 3:
                    ARnum[3]++;
                break;
            case 4:
                    ARnum[4]++;
                break;
            case 5:
                    ARnum[5]++;
                break;
                default:
                printf("\n ERROR \n");
                getchar();
                break;
            }
       }
       for(i=0;i<6;i++)
       {    printf("%d ",ARnum[i]);
        ARnum[i]=0;
       }

       printf("= 10,000 (avg = 1666), Test #%d\n",j);

    }/* end of for loop */
    return 0;
}

  • « windows simplest app
  • small linux lilo fdisk »

Published

Dec 3, 2004

Category

c

~88 words

Tags

  • c 95
  • integer 1
  • random 4