今日看到一个比较高效的取一个介于0~255之间随机整数的函数,与大伙分享一下 :)
//------------------Code_Start----------------------------------------------
static byte RndFactorA = 12;
static byte RndFactorB = 45;
int randInt()
{
RndFactorA += (RndFactorB & 0xFF);
RndFactorA += (RndFactorB & 0xFF) >>2 ;
RndFactorB ^= (RndFactorA & 0xFF);
RndFactorB += (RndFactorA & 0xFF) >>1 ;
return RndFactorA & 0xFF;
}
//--------------Code_End-----------------------------------------------------