一个随机数程序
时间:2010-12-17 来源:microsoftmvp
#include<iostream>
using namespace std;
static unsigned int Seed=1;
const int A=48241;
const int M=2147483647;
const int Q=M/A;
const int R=M%A;
const int W=7;
double Random()
{
long TmpSeed=A*(Seed%Q)-R*(Seed/Q);
if(TmpSeed>=0)
Seed=TmpSeed;
else
Seed=TmpSeed+M;
return (int)((double)Seed/M*97)%W;
}
int main()
{
for(int i=10;i<30;i++)
cout<<Random()<<endl;
return 0;
}
相关阅读 更多 +
排行榜 更多 +