Thread-safe random number generation in C++