fork download
  1. // Example program
  2. #include <iostream>
  3. #include <string>
  4. #include <cstdlib>
  5. #include <random>
  6.  
  7.  
  8. int generate_random_number_offscreen(int screen_size)
  9. {
  10. static std::default_random_engine gen;
  11. static std::uniform_int_distribution<int> dist(0, screen_size-1);
  12.  
  13. int r = dist(gen);
  14. if (dist(gen)%2 == 0) // pick between left of screen, or right of screen
  15. r -= screen_size; // range[-1000, -1] inclusive
  16. else
  17. r += screen_size; // range[1000, 1999] inclusive
  18.  
  19. return r;
  20. }
  21.  
  22. int main()
  23. {
  24. const int screen_size = 1000;
  25.  
  26. for (int i = 0; i < 10; i++)
  27. {
  28. std::cout << generate_random_number_offscreen(screen_size) << std::endl;
  29. }
  30. }
  31.  
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
1000
-245
-468
-953
-321
1383
-170
1053
1671
-617