rand_r (unsigned int *seed)函数的实现

                    rand_r(unsigned int *seed)函数的实现

int rand_r (unsigned int *seed)
{
 unsigned int next = *seed;
 int result;

 next *= 1103515245;
 next += 12345;
 result = (unsigned int) (next / 65536) % 2048;

 next *= 1103515245;
 next += 12345;
 result <<= 10;
 result ^= (unsigned int) (next / 65536) % 1024;

 next *= 1103515245;
 next += 12345;
 result <<= 10;
 result ^= (unsigned int) (next / 65536) % 1024;

 *seed = next;

 return result;
}

猜你喜欢

转载自blog.csdn.net/wsh6759/article/details/8545161