The problem is that by default, bind
will copy its argument to the closure, rather than create a reference to them. Random engines being copyable, you get two distinct engines that create the same numbers.
You need to wrap the generators in bind
with std::ref
. This tells bind
that you want to keep a reference to the engine, not make a copy of it.
function<int()> boundDist1 = std::bind(dist1, std::ref(generator));
function<int()> boundDist2 = std::bind(dist2, std::ref(generator));
Here's an ideone run with it.