/*
*Keil Lib
*2015.6.12
*Pass
*by lort
*/
uint32 Srandx ;
*Keil Lib
*2015.6.12
*Pass
*by lort
*/
uint32 Srandx ;
uint32 SrandK = 1103515245;//0x41C64E6D;
uint32 SrandB = 12345;//0x3039;
uint32 SrandB = 12345;//0x3039;
void os_srand(uint32 seek)
{
Srandx =seek;
}
uint32 os_rand (void)
{
Srandx = Srandx *SrandK +SrandB ;
return (Srandx>>1);
}
/*
*IAR Lib
*2015.6.13
*Pass
*by lort
*/
uint32 Srandx = 1;
uint32 SrandK = 0x0019660D;
uint32 SrandB = 0x3C6EF35F;
uint32 Srandy;
uint32 randTable[32];
void os_srand(uint16 seek)
{
uint8 i;
Srandx = seek;
for(i=0;i<8;i++)
{
Srandx = Srandx*SrandK+SrandB;
}
for(i=0;i<32;i++)
{
Srandx = Srandx*SrandK+SrandB;
randTable[i] = Srandx;
}
Srandy = Srandx;
}
uint16 os_rand(void)
{
uint8 id;
id = (Srandy&0x0000001f);
Srandx = Srandx*SrandK+SrandB;
Srandy = randTable[id];
randTable[id] = Srandx;//更新表
return (Srandy>>16)&0x7fff;
}