Answer the question
In order to leave comments, you need to log in
PSP sensor have questions?
Linear congruential generator Lemaire 1951
The most popular method for obtaining pseudo-random numbers is
the method of residues according to the formula:
U[i+1] = (U[i]*M)mod p = U[i]*M-p*int(U[i]*M/p)
R[i]=U[i]/p,где U[i],M,p-целые числа,0<R[i]<1,1<=U[i]<=p-1.
#include <iostream>
#include <vector>
const int M = 302;
const int p = 1003;
const float U0 = 0.5;
const int N = 10000;
std::vector<float> gen(float R0, int m, int p)
{
std::vector<float> R;
std::vector<float> U;
U.push_back(R0);
for (int i = 0; i < N; i++)
{
U.push_back(U.back()/*U[i]*/ * M - p*int(U.back()/*U[i]*/ * M / p));
float r_ = U[i] / p;
R.push_back(r_);
std::cout <<R.back()<<" ";
}
return R;
}
int main()
{
gen(U0,M,p);
std::cin.ignore();
return 0;
}
Answer the question
In order to leave comments, you need to log in
Question 1 how to check that if the sequence length is N=10000 (in principle, the length is not important) there are no repeating sequences? What can be used?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question