fork(5) download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. double GenerateRandom(double min, double max)
  7. {
  8. static bool first = true;
  9. if (first)
  10. {
  11. srand(time(NULL));
  12. first = false;
  13. }
  14. if (min > max)
  15. {
  16. std::swap(min, max);
  17. }
  18. return min + (double)rand() * (max - min) / (double)RAND_MAX;
  19. }
  20.  
  21. int main()
  22. {
  23. for (int i = 0; i < 10; ++i)
  24. {
  25. cout << GenerateRandom(-1.0, -2.0) << endl;
  26. }
  27. return 0;
  28. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
-1.10177
-1.18854
-1.68884
-1.14503
-1.79513
-1.84044
-1.76306
-1.03722
-1.48567
-1.75135