se consideri poi MAX_VAL (valore massimo) e MIN_VAL (valore minimo), puoi fare così:

(rand () % (MAX_VAL - MIN_VAL)) + MIN_VAL