utilize a função abaixo;
retorno: inteiro entre zero e limiteMax .
Precisa incluir as bibliotecas time.h e math.h
- int GeraNumeroAleatorio (int limiteMax)
{
int x;
float tmp;
srand( (unsigned)time( NULL ) );
x = rand();
if (x > limiteMax)
{- tmp = ((float)x/(float)RAND_MAX) * limiteMax;
x = floor(tmp);
}
return x;- tmp = ((float)x/(float)RAND_MAX) * limiteMax;
}