Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <typename T> T randomFrom(const T min, const T max)
- {
- static std::random_device rdev;
- static std::default_random_engine re(rdev());
- // Create a compile-time conditional 'dist_type' checking on whether the 'value' is a 'real_dist' or 'int_dist'
- typedef typename std::conditional<
- std::is_floating_point<T>::value,
- std::uniform_real_distribution<T>,
- std::uniform_int_distribution<T> > ::type dist_type;
- dist_type uni(min, max);
- return static_cast<T>(uni(re));
- }
Add Comment
Please, Sign In to add comment