Content deleted Content added
Fastfission (talk | contribs) No edit summary |
|||
Line 14:
[[Category:Pseudorandom number generators]]
The following is a simple C++ program that generates the random numbers given an initial remainder we refer to as Zo= Xn in our case above.
#include<iostream.h>
void main()
{
int n=0,a,c,m,Z[100];
float U[100];
cout<<"enter z "<<endl;
cin>>Z[0];
cout<<"enter a "<<endl;
cin>>a;
cout<<"enter c "<<endl;
cin>>c;
cout<<"enter m "<<endl;
cin>>m;
cout<<"n"<<"\t"<<"Zn"<<"\t"<<"Un"<<"\t"<<endl;
cout<<"..."<<"\t"<<"..."<<"\t"<<"..."<<"\t"<<endl;
do
{
Z[n+1]=((Z[n]*a)+c)%m;
if(Z[n+1]!=0)
U[n+1]=(float)1/(Z[n+1]);
else
Z[n+1]=0;
cout<<n<<"\t"<<Z[n+1]<<"\t"<<U[n+1]<<"\t"<<endl;
n++;
}
while(Z[n]!=Z[0]);
}
|