You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2018/12/09 17:29:04 UTC

[GitHub] perdasilva commented on a change in pull request #13574: Replaced rand_r with std:: random generation

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_r240045589
 
 

 ##########
 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:
   Could you add a RandInt method and use this in rnn_impl?
   Would be interested to get understand what happens memory-wise with these thread_locals when I see you next =)

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services