Ciao a tutti!
Secondo voi in C, come posso implementare una funzione che mi genere un numero random tra un intervallo di due valori che decido io? Ad es. tra 6 e 12.
Grazie...
int intRand(int, int);
int intRand(int iMin, int iMax)
{
int iResult;
iResult = iMin + rand() % (iMax - iMin + 1)
return iResult;
}
...
int iVal;
...
randomize();
...
iVal = intRand(6, 12); // genera un valore intero casuale compreso tra 6 e 12
int intRand(int, int);
int intRand(int iMin, int iMax)
{
return iMin + rand() % (iMax - iMin + 1)
}
...
int iVal;
...
srand(time(0));
...
iVal = intRand(6, 12); // genera un valore intero casuale compreso tra 6 e 12
Visitano il forum: Nessuno e 1 ospite