Is mersenne twister thread safe for cpp
问题 #include <random> int f() { std::random_device seeder; std::mt19937 engine(seeder()); std::uniform_int_distribution<int> dist(1, 6); return dist(engine); } Can multiple threads call this function safely? Is the function thread safe? It is reduntant to call std::random_device seeder; and std::mt19937 engine(seeder()); every time? 回答1: No C++ std type uses global data in a non-thread-safe way. Two unrelated instances of such a type can be accessed in different threads. By default, one instance