fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <iomanip>
  4. using namespace std;
  5.  
  6. int main() {
  7. int a = 5, c = 3, m = 16, X0 = 1;
  8. int n = 10;
  9. vector<int> numbers;
  10. vector<double> normalized;
  11.  
  12. int X = X0;
  13. cout << "Generated LCG numbers: ";
  14. for(int i = 0; i < n; i++) {
  15. X = (a * X + c) % m;
  16. numbers.push_back(X);
  17. cout << X << " ";
  18. }
  19. cout << endl;
  20.  
  21. cout << "Normalized numbers: ";
  22. for(int i = 0; i < n; i++) {
  23. double norm = static_cast<double>(numbers[i]) / (m - 1);
  24. normalized.push_back(norm);
  25. cout << fixed << setprecision(2) << norm << " ";
  26. }
  27. cout << endl;
  28.  
  29. bool repetition = false;
  30. for(int i = 0; i < n; i++) {
  31. for(int j = i+1; j < n; j++) {
  32. if(numbers[i] == numbers[j]) {
  33. repetition = true;
  34. break;
  35. }
  36. }
  37. if(repetition) break;
  38. }
  39. if(repetition) {
  40. cout << "There are repetitions in the sequence." << endl;
  41. } else {
  42. cout << "No repetitions in the sequence." << endl;
  43. }
  44.  
  45. return 0;
  46. }
  47.  
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
Generated LCG numbers: 8 11 10 5 12 15 14 9 0 3 
Normalized numbers: 0.53 0.73 0.67 0.33 0.80 1.00 0.93 0.60 0.00 0.20 
No repetitions in the sequence.