Advertisement
Gistrec

C++ STL Random

Mar 2nd, 2020
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <random>
  3.  
  4.  
  5. int main() {
  6.     using ElemT = float;
  7.  
  8.     // Predefined random number generators
  9.     // https://en.cppreference.com/w/cpp/numeric/random
  10.     std::mt19937_64 engine{ std::random_device{}() };
  11.  
  12.     // Random number distributions
  13.     // https://en.cppreference.com/w/cpp/numeric/random
  14.     std::normal_distribution<ElemT>      normal{ 0.0f, 0.5f };
  15.     std::exponential_distribution<ElemT> exp{ 1.0f };
  16.  
  17.     for (auto i : std::vector<ElemT>(10, 0.0f)) {
  18.         std::cout << exp(engine) << std::endl; 
  19.     }
  20.  
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement