fork download
  1. // Problem 1: Linear Congruential Generator (LCG)
  2.  
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int a, x, c, m;
  9. cin >> a >> x >> c >> m;
  10. for (int i = 1; i <= 10; i++)
  11. {
  12. x = (a * x + c) % m;
  13. cout << x << " ";
  14. }
  15. return 0;
  16. }
  17.  
  18. /*
  19.  
  20. 1. What is the sequence of generated random numbers?
  21. = 8 11 10 5 12 15 14 9 0 3
  22.  
  23. 2. Normalize them to the range [0, 1).
  24. = 0.08 0.11 0.1 0.05 0.12 0.15 0.14 0.09 0 0.03
  25.  
  26. 3. Are there any repetitions in the sequence?
  27. = No
  28.  
  29. */
  30.  
  31.  
Success #stdin #stdout 0.01s 5284KB
stdin
5 1 3 16
stdout
8 11 10 5 12 15 14 9 0 3