I found this program while looking through some old backups labeled red_floppy. I thought it was pretty funny how shitty of a coder I was at 13. I am also kind of amazed at how much of a dork I was for writing a program to help AD&D Character Generation.


#define D 6

int roll();
int * sort_roll(int u[]);
int score(int s[]);
void seed();

int roll()
{
    int z, x, rs[4], *rr, r;
    int j = 6;
    while(--j){
    for(x = 0; x < 4; x++)
    {
          rs[x] = ((int) D * rand() / (RAND_MAX + 1.0)) + 1;
          for (z = 0; z < 100; z++) rand();
    }
    rr = sort_roll(rs);
    r = score(rr);
    }
    return r;
}

int * sort_roll(int u[])
{
    int x,y,temp;

    for(x = 0;x < 4; x++)
    {
      for(y = 0;y < 4; y++)
      {
       if(u[x] < u[y])
       {
         temp = u[x];
         u[x] = u[y];
         u[y] = temp;
       }
      }
    }
    return u;
} 

int score(int s[])
{
    return s[1] + s[2] + s[3];
}

void seed()
{
     srand((unsigned int)time((time_t *)NULL));
}

int main()
{
  int x, j;
  seed();
  do{
  for(x = 0; x < 6; x++) printf("%d\n", roll());
  printf("\n\n");
  } while((j = toupper(getch()) == 'X'));
  system("pause");
  return 0;
}