Monday, October 17, 2011

Linear Congruential method ( Random Number generation )



#include
#include
#define true 1
#define false 0
void main()
{
int x[30];
int flag=true,i,a,c,m,x0;
float r[30];
printf("\n Enter a,c,m,x0");
scanf("%d%d%d%d",&a,&c,&m,&x0);
x[0]=x0;
i=1;
while(flag==true)
{
x[i]=(a*x[i-1]+c)%m;
r[i]=x[i]/(float)m;
if(x[i]==x[0])//Now onwards series will repeat
flag=false;
i++;
printf("x[i]=%d\n",x[i-1]);
}
getch();
}




omprakash sharma

4552/09

No comments:

Post a Comment