/* White noise generator. ./random > output.pgm */ #include #include #include #ifdef _WIN32 #include #include #endif int main(int argc, char **argv) { int width, height, x, y; if( argc != 3 || (width = atoi(argv[1])) <= 0 || (height = atoi(argv[2])) <= 0 ) { return printf("%s \n", *argv); } if( width >= 0x8000 || height >= 0x8000 ) return !puts("Output size too large."); #ifdef _WIN32 setmode(STDOUT_FILENO, O_BINARY); #endif srand(time(NULL)); printf("P5\n%d %d\n255\n", width, height); for(y = 0; y < height; y++) { for(x = 0; x < width; x++) fputc((int)(255.0 * rand() / RAND_MAX), stdout); } return 0; }