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

来源:互联网 发布:阿里云os安装应用失败 编辑:程序博客网 时间:2024/04/29 18:30

 

 

                    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;
}