MCPcopy Create free account
hub / github.com/ElementsProject/elements / GetRandomDuration

Function GetRandomDuration

src/random.h:74–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72/** Generate a uniform random duration in the range [0..max). Precondition: max.count() > 0 */
73template <typename D>
74D 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};
83constexpr auto GetRandMicros = GetRandomDuration<std::chrono::microseconds>;
84constexpr auto GetRandMillis = GetRandomDuration<std::chrono::milliseconds>;
85

Callers

nothing calls this directly

Calls 2

GetRandFunction · 0.85
countMethod · 0.80

Tested by

no test coverage detected