E
E
Evgeny Petryaev2019-03-15 19:20:23
C++ / C#
Evgeny Petryaev, 2019-03-15 19:20:23

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.

And the task itself:
Investigate for which U[0],p,M the length of the sequence of non-repeating numbers will be at least 10000, with "good" stochastic parameters. Determine whether the value of R[0], at M and p=const affects the static characteristics of the sensor. If it does, then determine the range of allowable values ​​U[0]. Present the results of testing the generator for the optimal values ​​p,M,U[0].
Actually, I will add the code now slowly and I need to make the R numbers themselves in the range from [0,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;
}

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? map,pair,set? explain I'm weak in collections?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2019-03-15
@jcmvbkbc

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?

The sequence will start repeating when the internal state of the generator is repeated. You can stick out the internal state of the generator and use the cycle search algorithm .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question