fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <set>
  4. using namespace std;
  5.  
  6. int main() {
  7. // Parameters
  8. int a = 5, c = 3, m = 16;
  9. int x = 1; // seed
  10. int n = 10; // number of values to generate
  11.  
  12. vector<int> generated;
  13. vector<double> normalized;
  14.  
  15. // Generate sequence
  16. for (int i = 0; i < n; i++) {
  17. x = (a * x + c) % m;
  18. generated.push_back(x);
  19. normalized.push_back((double)x / m);
  20. }
  21.  
  22. // Print results
  23. cout << "Generated numbers (X_n): ";
  24. for (int val : generated) cout << val << " ";
  25. cout << endl;
  26.  
  27. cout << "Normalized values (U_n): ";
  28. for (double val : normalized) cout << val << " ";
  29. cout << endl;
  30.  
  31. // Check for repetitions
  32. set<int> uniq(generated.begin(), generated.end());
  33. if (uniq.size() < generated.size())
  34. cout << "There are repetitions in the sequence." << endl;
  35. else
  36. cout << "No repetitions in the first 10 numbers." << endl;
  37.  
  38. return 0;
  39. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Generated numbers (X_n): 8 11 10 5 12 15 14 9 0 3 
Normalized values (U_n): 0.5 0.6875 0.625 0.3125 0.75 0.9375 0.875 0.5625 0 0.1875 
No repetitions in the first 10 numbers.