fork download
  1. #include <iostream>
  2. #include <random>
  3. using namespace std;
  4.  
  5. float random(float a, float b)
  6. {
  7. static mt19937 gen(random_device{}());
  8. uniform_real_distribution<float> dis(a,b);
  9. return dis(gen);
  10. }
  11.  
  12.  
  13. int main()
  14. {
  15. for(int i = 0; i < 10; i++) cout << random(1,2) << " ";
  16. cout << endl;
  17. for(int i = 0; i < 10; i++) cout << random(8,9) << " ";
  18. }
Success #stdin #stdout 0s 5368KB
stdin
Standard input is empty
stdout
1.87145 1.60509 1.76489 1.4999 1.1254 1.91844 1.18764 1.39634 1.7307 1.69862 
8.42356 8.60911 8.08507 8.29672 8.93305 8.70739 8.88018 8.88398 8.25546 8.21311