fork download
  1. #include <iostream>
  2. #include <random>
  3. #include <chrono>
  4. class Test{
  5. public:
  6. Test(std::mt19937& rng): m_rng(rng){
  7. }
  8.  
  9. std::mt19937& m_rng;
  10. double randomNumber(double min, double max){
  11. std::uniform_real_distribution<double> uniformDistribution(min, max);
  12. return uniformDistribution(m_rng);
  13. }
  14.  
  15. };
  16.  
  17. int main() {
  18. std::mt19937 rng{std::chrono::high_resolution_clock::now().time_since_epoch().count()};
  19. Test a(rng);
  20. Test b(rng);
  21. for(int i=0; i<10; ++i){
  22. std::cout<< "a: " << a.randomNumber(0.0,1.0) << "b: " << b.randomNumber(5.0,6.0) << std::endl;
  23. }
  24. return 0;
  25. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
a: 0.839538b: 5.49571
a: 0.660106b: 5.89344
a: 0.350274b: 5.33347
a: 0.917049b: 5.42596
a: 0.249575b: 5.24575
a: 0.45779b: 5.44715
a: 0.293774b: 5.9544
a: 0.693205b: 5.27926
a: 0.329144b: 5.60904
a: 0.857501b: 5.90939