Advertisement
akela43

simple_random_functions

Dec 1st, 2021
797
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. std::default_random_engine & global_urng( )
  2. {
  3. static std::default_random_engine u{};
  4. return u;
  5. }
  6. void randomize( )
  7. {
  8.     static std::random_device rd{};
  9.     global_urng().seed( rd() );
  10. }
  11. int pick( int from, int thru )
  12. {
  13. static std::uniform_int_distribution<> d{};
  14.  using parm_t = decltype(d)::param_type;
  15.  return d( global_urng(), parm_t{from, thru} );
  16. }
  17. double pick( double from, double upto )
  18. {
  19.  static std::uniform_real_distribution<> d{};
  20.  using parm_t = decltype(d)::param_type;
  21.  return d( global_urng(), parm_t{from, upto} );
  22.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement