fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <random>
  4.  
  5. int main() {
  6.  
  7. std::mt19937 rnd{std::random_device{}()}; // Probably created in main
  8.  
  9. const std::vector<double> ys = {-0.2, -0.3, -0.4, 0.4, 0.5};
  10. std::uniform_int_distribution<> dis(0, ys.size() - 1);
  11.  
  12. for (int i = 0; i != 10; ++i) {
  13. double y = ys[dis(rnd)];
  14. std::cout << y << std::endl;
  15. }
  16. }
Success #stdin #stdout 0s 4552KB
stdin
Standard input is empty
stdout
0.5
-0.4
-0.2
-0.3
-0.3
0.5
-0.3
-0.2
-0.4
-0.2