fork download
  1. #include <random>
  2. #include <iostream>
  3.  
  4. struct mygen
  5. {
  6. mygen(double low, double high) : dist(low, high) {}
  7. double operator()()
  8. {
  9. return dist(engine);
  10. }
  11. private:
  12. std::mt19937 engine;
  13. std::uniform_real_distribution<> dist;
  14. };
  15.  
  16. int main()
  17. {
  18. static mygen instance(18.3, 18.34);
  19. for(int i=0; i < 10; i++)
  20. {
  21. std::cout << " " << instance();
  22. }
  23. }
  24.  
  25.  
Success #stdin #stdout 0s 2828KB
stdin
Standard input is empty
stdout
 18.3054 18.3334 18.3388 18.3088 18.3123 18.3219 18.3075 18.3397 18.3399 18.3387