ok, grazie mille!!!
Si, lo so. Ma perché fa 15 shift?
Il fatto é che il numero restituito da rand varia a seconda della variabile RAND_MAX.
Io ho trovato un altro codice simile che fa cosí:
codice:
static int my_random(int max) // Return Random Int Between 0 and max
{
long temp;
#if defined(__OS_Win_) //For Windoze
temp = (long) rand();
#else // This is for unix
temp = random() >> 16;
#endif
temp = temp * (long) max;
temp = temp >> 15;
return (int) temp;
}
static MY_FLOAT noise_tick() // Return random MY_FLOAT float between -1.0 and 1.0
{
MY_FLOAT temp;
temp = my_random(32767) - 16384;
temp *= 0.0000610352;
return temp;
}
Mi chiedevo se puó andare bene anche questo codice che io ho scritto, (il mio obiettivo é
ottenere un numero che varia tra -1 e 1), e vorrei sapere se é meglio degli altri e perché....help!
codice:
//noise maker
float noise_tick() // Return random float between -1.0 and 1.0
{
float output;
output = (float)rand() - RAND_MAX/2;
output *= ONE_OVER_RANDLIMIT;
return output;
}
dove ONE_OVER_RANDLIMIT é pari a 1/RAND_MAX
Vi ringrazio