Blob Blame History Raw
From efa64416a06ad03e0444700376f02ea890378fb2 Mon Sep 17 00:00:00 2001
From: Peter Lemenkov <lemenkov@gmail.com>
Date: Tue, 12 Mar 2019 17:17:08 +0300
Subject: [PATCH] Don't use compat wrapper over random and rand

Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>

diff --git a/src/couchdb/Makefile.am b/src/couchdb/Makefile.am
index f069479bb..f0a7b2f0d 100644
--- a/src/couchdb/Makefile.am
+++ b/src/couchdb/Makefile.am
@@ -65,7 +65,6 @@ source_files = \
     couch_passwords.erl \
     couch_primary_sup.erl \
     couch_query_servers.erl \
-    couch_rand.erl \
     couch_ref_counter.erl \
     couch_secondary_sup.erl \
     couch_server.erl \
@@ -123,7 +122,6 @@ compiled_files = \
     couch_passwords.beam \
     couch_primary_sup.beam \
     couch_query_servers.beam \
-    couch_rand.beam \
     couch_ref_counter.beam \
     couch_secondary_sup.beam \
     couch_server.beam \
diff --git a/src/couchdb/couch_rand.erl b/src/couchdb/couch_rand.erl
deleted file mode 100644
index a57c0d6fa..000000000
--- a/src/couchdb/couch_rand.erl
+++ /dev/null
@@ -1,73 +0,0 @@
-% Licensed under the Apache License, Version 2.0 (the "License"); you may not
-% use this file except in compliance with the License. You may obtain a copy of
-% the License at
-%
-%   http://www.apache.org/licenses/LICENSE-2.0
-%
-% Unless required by applicable law or agreed to in writing, software
-% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-% License for the specific language governing permissions and limitations under
-% the License.
-
--module(couch_rand).
-
-
--export([
-    uniform/0,
-    uniform/1
-]).
-
-
--define(MIN_OTP_VERSION_WITH_RAND_MODULE, 18).
-
-
-has_rand_module() ->
-    OtpRelease = case erlang:system_info(otp_release) of
-        % < R15 is excluded by ./configure already
-        "R15" ++ _OtpVsn -> 15;
-        "R16" ++ _OtpVsn -> 16;
-        Release -> list_to_integer(Release)
-    end,
-    OtpRelease >= ?MIN_OTP_VERSION_WITH_RAND_MODULE.
-
-
-uniform() ->
-    case has_rand_module() of
-        true -> rand_uniform();
-        _False -> norand_uniform()
-    end.
-
-uniform(N) ->
-    case has_rand_module() of
-        true -> rand_uniform(N);
-        _False -> norand_uniform(N)
-    end.
-
-
-norand_uniform() ->
-    maybe_set_random_seed(),
-    random:uniform().
-
-
-norand_uniform(N) ->
-    maybe_set_random_seed(),
-    random:uniform(N).
-
-
-maybe_set_random_seed() ->
-    case get(random_seed) of
-        undefined ->
-            {_, Sec, USec} = os:timestamp(),
-            Seed = {erlang:phash2(self()), Sec, USec},
-            random:seed(Seed);
-        _ ->
-            ok
-    end.
-
-rand_uniform() ->
-    rand:uniform().
-
-
-rand_uniform(N) ->
-    rand:uniform(N).
diff --git a/test/couchdb/couch_btree_tests.erl b/test/couchdb/couch_btree_tests.erl
index 6a94d41fb..672699450 100644
--- a/test/couchdb/couch_btree_tests.erl
+++ b/test/couchdb/couch_btree_tests.erl
@@ -82,7 +82,7 @@ btree_open_test_() ->
 
 sorted_kvs_test_() ->
     Funs = kvs_test_funs(),
-    Sorted = [{Seq, couch_rand:uniform()} || Seq <- lists:seq(1, ?ROWS)],
+    Sorted = [{Seq, rand:uniform()} || Seq <- lists:seq(1, ?ROWS)],
     {
         "BTree with sorted keys",
         {
@@ -93,7 +93,7 @@ sorted_kvs_test_() ->
     }.
 
 rsorted_kvs_test_() ->
-    Sorted = [{Seq, couch_rand:uniform()} || Seq <- lists:seq(1, ?ROWS)],
+    Sorted = [{Seq, rand:uniform()} || Seq <- lists:seq(1, ?ROWS)],
     Funs = kvs_test_funs(),
     Reversed = Sorted,
     {
@@ -107,7 +107,7 @@ rsorted_kvs_test_() ->
 
 shuffled_kvs_test_() ->
     Funs = kvs_test_funs(),
-    Sorted = [{Seq, couch_rand:uniform()} || Seq <- lists:seq(1, ?ROWS)],
+    Sorted = [{Seq, rand:uniform()} || Seq <- lists:seq(1, ?ROWS)],
     Shuffled = shuffle(Sorted),
     {
         "BTree with shuffled keys",
@@ -463,7 +463,7 @@ randomize(T, List) ->
         end, randomize(List), lists:seq(1, (T - 1))).
 
 randomize(List) ->
-    D = lists:map(fun(A) -> {couch_rand:uniform(), A} end, List),
+    D = lists:map(fun(A) -> {rand:uniform(), A} end, List),
     {_, D1} = lists:unzip(lists:keysort(1, D)),
     D1.
 
diff --git a/test/couchdb/couch_file_tests.erl b/test/couchdb/couch_file_tests.erl
index 5ef13c9d6..cedf9273d 100644
--- a/test/couchdb/couch_file_tests.erl
+++ b/test/couchdb/couch_file_tests.erl
@@ -253,13 +253,13 @@ check_header_recovery(CheckFun) ->
     ok.
 
 write_random_data(Fd) ->
-    write_random_data(Fd, 100 + couch_rand:uniform(1000)).
+    write_random_data(Fd, 100 + rand:uniform(1000)).
 
 write_random_data(Fd, 0) ->
     {ok, Bytes} = couch_file:bytes(Fd),
     {ok, (1 + Bytes div ?BLOCK_SIZE) * ?BLOCK_SIZE};
 write_random_data(Fd, N) ->
     Choices = [foo, bar, <<"bizzingle">>, "bank", ["rough", stuff]],
-    Term = lists:nth(couch_rand:uniform(4) + 1, Choices),
+    Term = lists:nth(rand:uniform(4) + 1, Choices),
     {ok, _, _} = couch_file:append_term(Fd, Term),
     write_random_data(Fd, N - 1).