[ 
https://issues.apache.org/jira/browse/ARROW-1750?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16239710#comment-16239710
 ] 

ASF GitHub Bot commented on ARROW-1750:
---------------------------------------

cpcloud commented on a change in pull request #1283: ARROW-1750: [C++] Remove 
the need for arrow/util/random.h
URL: https://github.com/apache/arrow/pull/1283#discussion_r148969326
 
 

 ##########
 File path: cpp/src/arrow/test-util.h
 ##########
 @@ -143,56 +140,104 @@ static inline Status GetBitmapFromVector(const 
std::vector<T>& is_valid,
 // Sets approximately pct_null of the first n bytes in null_bytes to zero
 // and the rest to non-zero (true) values.
 static inline void random_null_bytes(int64_t n, double pct_null, uint8_t* 
null_bytes) {
-  Random rng(random_seed());
-  for (int64_t i = 0; i < n; ++i) {
-    null_bytes[i] = rng.NextDoubleFraction() > pct_null;
-  }
+  const int random_seed = 0;
+  std::mt19937 gen(random_seed);
+  std::uniform_real_distribution<double> d(0.0, 1.0);
+  std::generate(null_bytes, null_bytes + n,
+                [&d, &gen, &pct_null] { return d(gen) > pct_null; });
 }
 
 static inline void random_is_valid(int64_t n, double pct_null,
                                    std::vector<bool>* is_valid) {
-  Random rng(random_seed());
-  for (int64_t i = 0; i < n; ++i) {
-    is_valid->push_back(rng.NextDoubleFraction() > pct_null);
-  }
+  const int random_seed = 0;
+  std::mt19937 gen(random_seed);
+  std::uniform_real_distribution<double> d(0.0, 1.0);
+  is_valid->resize(n, false);
+  std::generate(is_valid->begin(), is_valid->end(),
+                [&d, &gen, &pct_null] { return d(gen) > pct_null; });
 }
 
 static inline void random_bytes(int64_t n, uint32_t seed, uint8_t* out) {
   std::mt19937 gen(seed);
-  std::uniform_int_distribution<int> d(0, 255);
+  std::uniform_int_distribution<int> d(0, std::numeric_limits<uint8_t>::max());
+  std::generate(out, out + n, [&d, &gen] { return static_cast<uint8_t>(d(gen) 
& 0xFF); });
+}
 
-  for (int64_t i = 0; i < n; ++i) {
-    out[i] = static_cast<uint8_t>(d(gen) & 0xFF);
+static void DecimalRange(int32_t precision, Decimal128* min_decimal,
+                         Decimal128* max_decimal) {
+  DCHECK_GE(precision, 1) << "decimal precision must be greater than or equal 
to 1, got "
+                          << precision;
+  DCHECK_LE(precision, 38) << "decimal precision must be less than or equal to 
38, got "
+                           << precision;
+  DCHECK_NE(min_decimal, NULLPTR);
+  DCHECK_NE(max_decimal, NULLPTR);
+
+  *max_decimal = 1;
+  for (int32_t i = 0; i < precision; ++i) {
+    *max_decimal *= 10;
 
 Review comment:
   After ARROW-1749 is merged, this will need to be rewritten.

----------------------------------------------------------------
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]


> [C++] Remove the need for arrow/util/random.h
> ---------------------------------------------
>
>                 Key: ARROW-1750
>                 URL: https://issues.apache.org/jira/browse/ARROW-1750
>             Project: Apache Arrow
>          Issue Type: Improvement
>          Components: C++
>    Affects Versions: 0.7.1
>            Reporter: Phillip Cloud
>            Assignee: Phillip Cloud
>            Priority: Minor
>              Labels: pull-request-available
>             Fix For: 0.8.0
>
>
> The C++ stdlib provides APIs for everything this is currently being used for.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to