I need to build a bar gragh that illustrate a distribution of pseudorandom numbers that determined by linear congruential method
Xn+1 = (a * Xn + c) mod m
U = X/m
on the interval [0,1]
For example:
Interval Frequency
[0;0,1] 0,05
[0,1;0,2] 0,15
[0,2;0,3] 0,1
[0,3;0,4] 0,12
[0,4;0,5] 0,1
[0,5;0,6] 0,15
[0,6;0,7] 0,05
[0,7;0,8] 0,08
[0,8;0,9] 0,16
[0,9;1,0] 0,4
I used such a method:
float mas[10] = {0,0,0,0,0,0,0,0,0,0};
void metod1()
{
int x=-2, m=437, a=33, c=61;
float u;
for(int i=0;i<m;i++){
x=(a*x + c) % m;
u=(float)x/(float)m;
int r;
r = ceil(u*10);
mas[r] = mas[r] + 1;
}
for(i=0;i<10;i++) cout<<"["<<(float)i/10<<";"<<(float)(i+1)/10<<"]"<<" | "<<mas[i]<<"\n-----------------"<<endl;
return;
}
If you know another officient methods for this problem, that are not straitforward, i would appreciate it.