2007年7月19日 星期四

這段code 的意思看不懂

int
stunRand()
{
// return 32 bits of random stuff
assert( sizeof(int) == 4 );
static bool init=false;
if ( !init )
{
init = true;

UInt64 tick;

#if defined(WIN32)
volatile unsigned int lowtick=0,hightick=0;
__asm
{
rdtsc
mov lowtick, eax
mov hightick, edx
}
tick = hightick;
tick <<= 32;
tick |= lowtick;
#else
asm("rdtsc" : "=A" (tick));
#endif
int seed = int(tick);
#ifdef WIN32
srand(seed);
#else
srandom(seed);
#endif
}

#ifdef WIN32
assert( RAND_MAX == 0x7fff );
int r1 = rand();
int r2 = rand();

int ret = (r1<<16) + r2;

return ret;
#else
return random();
#endif
}

尤其是

asm("rdtsc" : "=A" (tick));
int seed = int(tick);

不太懂

沒有留言: