| 72 | /** Generate a uniform random duration in the range [0..max). Precondition: max.count() > 0 */ |
| 73 | template <typename D> |
| 74 | D GetRandomDuration(typename std::common_type<D>::type max) noexcept |
| 75 | // Having the compiler infer the template argument from the function argument |
| 76 | // is dangerous, because the desired return value generally has a different |
| 77 | // type than the function argument. So std::common_type is used to force the |
| 78 | // call site to specify the type of the return value. |
| 79 | { |
| 80 | assert(max.count() > 0); |
| 81 | return D{GetRand(max.count())}; |
| 82 | }; |
| 83 | constexpr auto GetRandMicros = GetRandomDuration<std::chrono::microseconds>; |
| 84 | constexpr auto GetRandMillis = GetRandomDuration<std::chrono::milliseconds>; |
| 85 | |