Advertisement
Guest User

Untitled

a guest
Feb 19th, 2012
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <random>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. template <typename Generator>
  8. double randomDoubleEngine(Generator& engine, double low_bound, double high_bound )
  9. {
  10.     if (low_bound > high_bound){
  11.         std::swap(low_bound, high_bound);
  12.     }
  13.  
  14.     return std::uniform_real_distribution<>( low_bound, high_bound )( engine );
  15. }
  16.  
  17.  
  18. void doSomething(){
  19.  
  20.     //std::mt19937 engine;
  21.  
  22.     std::random_device rd;
  23.     std::mt19937 engine(rd());
  24.  
  25.     double low = -1.7411500;
  26.     double high = 2.2737999;
  27.     for(int i =0; i < 20; i++){
  28.         std::cout << randomDoubleEngine(engine, low, high ) << std::endl;
  29.     }
  30. }
  31.  
  32. int main(){
  33.  
  34.  
  35.     for(int i = 0; i < 5; i++){
  36.         std::cout << "####################################\n";
  37.         std::cout << "# Call number: "  << i  << "\n";
  38.         doSomething();
  39.         std::cout << "####################################\n\n";
  40.     }
  41.  
  42.  
  43.  
  44.     return (EXIT_SUCCESS);
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement