#include #include #include #include #include #define DEFSIZE 10 #define MAXSIZE 70 int main (int argc, char **argv) { int file, digits = -1, i; long unsigned int value; size_t size; // Se abre /dev/random file = open("/dev/random", O_RDONLY); if (file == -1) {perror("open"); exit(EXIT_FAILURE);} // Se obtiene el número de fígitos if (argc > 1) digits = atoi(argv[1]); if (digits <= 0) digits = DEFSIZE; if (digits > MAXSIZE) digits = MAXSIZE; // Se obtienen e imprimen los valores aleatorios desde random size = sizeof(value); do { if (read(file, &value, size) == -1) {perror("read"); exit(EXIT_FAILURE);} if (digits > 5) {value=value%100000; digits=digits-5; printf("%05lu",value);} else {value=value%10; digits=digits-1; printf("%1lu",value);} } while (digits > 0); putchar('\n'); exit(EXIT_SUCCESS); // Y fin }