fork(30) download
  1. #include <iostream>
  2. #include <random>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. // Random seed
  8. random_device rd;
  9.  
  10. // Initialize Mersenne Twister pseudo-random number generator
  11. mt19937 gen(rd());
  12.  
  13. // Generate pseudo-random numbers
  14. // uniformly distributed in range (1, 100)
  15. uniform_int_distribution<> dis(1, 100);
  16.  
  17. // Generate ten pseudo-random numbers
  18. for (int i = 0; i < 10; i++)
  19. {
  20. int randomX = dis(gen);
  21. cout << "\nRandom X = " << randomX;
  22. }
  23. }
  24.  
Success #stdin #stdout 0s 3272KB
stdin
Standard input is empty
stdout
Random X = 71
Random X = 57
Random X = 75
Random X = 13
Random X = 33
Random X = 54
Random X = 87
Random X = 42
Random X = 79
Random X = 42