Use FastRandomContext instead of boost::random::{mt19937,uniform_int_distribution}.
Was:
Use
std::random::mt19937/uniform_int_distribution(C++11) instead ofboost::randomequivalents.
Use FastRandomContext instead of boost::random::{mt19937,uniform_int_distribution}.
Was:
Use
std::random::mt19937/uniform_int_distribution(C++11) instead ofboost::randomequivalents.
Why not use our own FastRandomContext? This only uses linear random, so I'd say there's no need to add a dependency on std::random::mt19937.
(though getting rid of the boost one is good...)
@laanwj Good idea! Now using FastRandomContext. Looks OK now?
Yes, that's a cool minimal-impact solution using the lambda expressions.
59 | - boost::random::uniform_int_distribution<> randomMsec(-11, 1000); 60 | - boost::random::uniform_int_distribution<> randomDelta(-1000, 1000); 61 | + FastRandomContext rng(42); 62 | + auto zeroToNine = [](FastRandomContext& rc) { return rc.randrange(10); }; // [0, 9] 63 | + auto randomMsec = [](FastRandomContext& rc) { return -11 + rc.randrange(1012); }; // [-11, 1000] 64 | + auto randomDelta = [](FastRandomContext& rc) { return -1000 + rc.randrange(2001); }; // [-1000, 1000]
This lambda returns an unsigned expression and such can never be negative.
Good catch, hadn't realized randrange returns an unsigned value. This is a risk with auto.
@MarcoFalke Oh, good catch! Now explicitly setting the return type. Thanks a lot for noticing!
utACK
utACK 227ae9b34dce632e42ca9f22139e6efad0485df1. Great use of lambdas.