/* Seed the random-number generator with current time so that * the numbers will be different every time we run. */ // srand( (unsigned)time( NULL ) );
i = rand(); i = abs(i); if(i > 20) { iRGB = i%20; }
return iRGB; }
srand( (unsigned)time( NULL ) ); int i = rand(); i = i%21; 这样i就是0到20间的整数了
呵呵,参考:
int i;
/* Seed the random-number generator with current time so that
* the numbers will be different every time we run.
*/
// srand( (unsigned)time( NULL ) );
i = rand();
i = abs(i);
if(i > 20)
{
iRGB = i%20;
}
return iRGB;
}
int i = rand();
i = i%21;
这样i就是0到20间的整数了