void generate_random_page(char *page) { unsigned int i; switch (rand() % 6) { /* return a page of complete trash */ case 0: /* bytes */ for (i = 0; i < page_size; ) page[i++] = (unsigned char)rand(); return; case 1: /* words */ for (i = 0; i < (page_size / 2); ) { page[i++] = 0; page[i++] = (unsigned char)rand(); } return; case 2: /* ints */ for (i = 0; i < (page_size / 4); ) { page[i++] = 0; page[i++] = 0; page[i++] = 0; page[i++] = (unsigned char)rand(); } return; /* return a page that looks kinda like a struct */ case 3: fabricate_onepage_struct(page); return; /* return a page of unicode nonsense. */ case 4: gen_unicode_page(page); return; /* page of 0's and 1's. */ case 5: for (i = 0; i < page_size; ) page[i++] = (unsigned char)rand() % 2; return; default: BUG("unreachable!\n"); return; } }
void main(int argc, char* argv[]) { unsigned char *page; unsigned int x = 0, y, n = 0; struct timeval t; gettimeofday(&t, 0); srand((t.tv_sec * getpid()) ^ t.tv_usec); page = malloc(4096); memset(page, 0, 4096); gen_unicode_page(page); for (y = 0; y < 4096; y+=32) { for (x = 0; x < 32; x++) { printf("%c", page[n++]); } } }