Ci sarebbero molte considerazioni da fare sulla funzione rand(), se vuoi approfondire il discorso leggi Misconceptions about rand.