ho trovato questo piccolo esempio, ma non capisco bene come fare a generare dei numeri in un certo range (0-255), posso usare dev/random urandom con srand per il seeder e generare i numeri usando rand()%numero?
esempio:
#include <stdio.h>
//#include <stdlib.h>
#include <fcntl.h>
#include <time.h>
//#include <math.h>
main (void) {
int randnum;
int fd = open ("/dev/urandom", O_RDONLY);
if (fd != -1) {
read( fd, &randnum, 4 );
randnum = abs( randnum ); /* If you only want positive values */
printf("Random number : %d\n",randnum);
close(fd);
} else {
/* Please don't do this if you need cryptographic security! */
randnum = time(NULL) + getpid(); // + other weird stuff;
}
//seed_the_rng_function(randnum);
system("pause");
}