perdasilva commented on a change in pull request #13574: Replaced rand_r with
std:: random generation
URL: https://github.com/apache/incubator-mxnet/pull/13574#discussion_r251722907
##########
File path: tests/cpp/include/test_ndarray_utils.h
##########
@@ -54,9 +55,11 @@ inline unsigned gen_rand_seed() {
}
inline float RandFloat() {
- static unsigned seed = gen_rand_seed();
- double v = rand_r(&seed) * 1.0 / RAND_MAX;
- return static_cast<float>(v);
+ static thread_local std::random_device device;
+ static thread_local std::default_random_engine generator(device());
+ static thread_local std::uniform_real_distribution<float> distribution;
+ static thread_local auto dice = std::bind(distribution, generator);
+ return dice();
}
Review comment:
There's no facepalm emoticon, so I had thumbs-up
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services