From eb068fbfca831b2e6471bc1b983a244428ffeded Mon Sep 17 00:00:00 2001
From: Gunhan Gulsoy <gunan@google.com>
Date: Sat, 11 Jan 2020 14:30:37 -0800
Subject: [PATCH] Remove uses of rand_r in quantize/dequantize op_test.

rand_r is not available on windows.

PiperOrigin-RevId: 289270961
Change-Id: I94a287bbcf213fd1656d8e34636c23339db2b219
---
 tensorflow/core/kernels/dequantize_op_test.cc | 4 +++-
 tensorflow/core/kernels/quantize_op_test.cc   | 5 ++++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/tensorflow/core/kernels/dequantize_op_test.cc b/tensorflow/core/kernels/dequantize_op_test.cc
index 06269e6e965..3c9d1790787 100644
--- a/tensorflow/core/kernels/dequantize_op_test.cc
+++ b/tensorflow/core/kernels/dequantize_op_test.cc
@@ -15,6 +15,7 @@ limitations under the License.
 
 #include <functional>
 #include <memory>
+#include <random>
 #include <vector>
 
 #include "tensorflow/cc/ops/array_ops.h"
@@ -128,6 +129,7 @@ class DequantizeOpTest : public OpsTestBase {
   std::vector<T> ScalePerSliceAlongAxis(std::vector<int64> dims, int axis,
                                         const std::vector<T>& data) {
     uint32 seed = 123;
+    std::minstd_rand rng(seed);
     int64 out_size = 1;
     for (int dim : dims) {
       out_size *= dim;
@@ -139,7 +141,7 @@ class DequantizeOpTest : public OpsTestBase {
     std::vector<T> out(out_size);
     int num_slices = (axis == -1) ? 1 : dims[axis];
     for (int out_idx = 0; out_idx < out_size; ++out_idx) {
-      int in_idx = rand_r(&seed) % data.size();
+      int in_idx = rng() % data.size();
       T multiplier = ((out_idx / minor_size) % num_slices) + 1;
       out[out_idx] = data[in_idx] * multiplier;
     }
diff --git a/tensorflow/core/kernels/quantize_op_test.cc b/tensorflow/core/kernels/quantize_op_test.cc
index 6244df8d754..e4488fc431b 100644
--- a/tensorflow/core/kernels/quantize_op_test.cc
+++ b/tensorflow/core/kernels/quantize_op_test.cc
@@ -13,6 +13,8 @@ See the License for the specific language governing permissions and
 limitations under the License.
 ==============================================================================*/
 
+#include <random>
+
 #include "tensorflow/core/framework/fake_input.h"
 #include "tensorflow/core/framework/node_def_builder.h"
 #include "tensorflow/core/framework/tensor.h"
@@ -61,6 +63,7 @@ template <typename T>
 std::vector<T> ScalePerSliceAlongAxis(std::vector<int64> dims, int axis,
                                       const std::vector<T>& data) {
   uint32 seed = 123;
+  std::minstd_rand rng(seed);
   int64 out_size = 1;
   for (int dim : dims) {
     out_size *= dim;
@@ -72,7 +75,7 @@ std::vector<T> ScalePerSliceAlongAxis(std::vector<int64> dims, int axis,
   std::vector<T> out(out_size);
   int num_slices = (axis == -1) ? 1 : dims[axis];
   for (int out_idx = 0; out_idx < out_size; ++out_idx) {
-    int in_idx = rand_r(&seed) % data.size();
+    int in_idx = rng() % data.size();
     T multiplier = ((out_idx / minor_size) % num_slices) + 1;
     out[out_idx] = data[in_idx] * multiplier;
   }