I14 Answer


/* Make all pixels of an image the same value */
void randImage( image img, int min, int max )
{
  int r, c;

  for ( r = 0; r<img.nrows; r++ )
    for ( c = 0; c<img.ncols; c++ )
      setPixel( img, r, c, (unsigned char)randInt(min, max) );
}

Comments: The complete program is nearly the same as for the previous puzzles, but includes the above function. Initializing the random number generator should be done in main(), where the programmer may wish specify a particular seed for the generator.

The randInt() function comes from puzzle B05:

/* Generate a random integer  min <= r <= max */
int randInt( int min, int max )
{
  int num;
  num = (rand()*(max-min+1))/(RAND_MAX+1) + min ;
  
  return num;
}

back