#include #include #include #include #include #include #include static int nbytes = 20; static char *method = NULL; static char *progname = NULL; static int loops = 100; static void help(void) { printf("%s [dev|random] nbytes loops\n", progname); } static void calc_dev(void) { int i, f; char *data = malloc(nbytes); for (i = 0; i < loops; i++) { f = open("/dev/urandom", O_RDONLY, 0); if (f == -1) { fprintf(stderr, "Failed to open /dev/urandom\n"); exit(1); } (void) read(f, data, nbytes); close(f); } free(data); } static void calc_random(void) { long rand; int i, j; char data; for (i = 0; i < loops; i++) { for (j = 0; j < nbytes; j++) { rand = random(); data = (rand % 255) + 1; } } } int main(int argc, char **argv) { progname = strdup(argv[0]); if (argc != 4) { fprintf(stderr, "Meh\n"); exit(1); } nbytes = atoi(argv[2]); loops = atoi(argv[3]); printf("nbytes = %d, loops = %d\n", nbytes, loops); if (strcmp(argv[1], "dev") == 0) calc_dev(); else if (strcmp(argv[1], "random") == 0) calc_random(); else { fprintf(stderr, "Incorrect method\n"); exit(1); } }