/* generatori random 'umani' per uniforme discreta e continua File con sole funzioni Compilare con "gcc -c random_lib.c" */ #include #include // per la random #include // per il seed //---------------------------------------------- void setRandomSeed( unsigned RandomSeed) { time_t t; if (RandomSeed == 0 ) { // se == 0 si usa il tempo RandomSeed = (unsigned) time(&t); } printf("seed %u\n", RandomSeed ); srand( RandomSeed ); } int irunif(int min, int max) { if(min >= max) return(0); return( min + rand() % (max-min+1) ); } //--------------------------------------------- float frunif(float min, float max) { float rzerouno; if(min >= max) return(0); rzerouno = (float) rand() / (float) RAND_MAX; return( min + rzerouno * (max-min) ); }