Skip to content

Commit aca60dd

Browse files
committed
Remove compat couch_rand module
It's not needed any longer as `rand` is in all the currently supported Erlang releases.
1 parent b85d4bb commit aca60dd

16 files changed

+22
-46
lines changed

src/couch/src/couch_debug.erl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ random_processes(Acc, Depth) ->
11371137
end.
11381138

11391139
oneof(Options) ->
1140-
lists:nth(couch_rand:uniform(length(Options)), Options).
1140+
lists:nth(rand:uniform(length(Options)), Options).
11411141

11421142
tree() ->
11431143
[InitialPid | _] = Processes = random_processes(5),

src/couch/src/couch_multidb_changes.erl

+1-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ notify_fold(DbName, {Server, DbSuffix, Count}) ->
373373
% number of shards back to back during startup.
374374
jitter(N) ->
375375
Range = min(2 * N * ?AVG_DELAY_MSEC, ?MAX_DELAY_MSEC),
376-
couch_rand:uniform(Range).
376+
rand:uniform(Range).
377377

378378
scan_local_db(Server, DbSuffix) when is_pid(Server) ->
379379
case couch_server:exists(DbSuffix) of

src/couch/src/couch_rand.erl

-24
This file was deleted.

src/couch/src/couch_uuids.erl

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ new_prefix() ->
8888
couch_util:to_hex((crypto:strong_rand_bytes(13))).
8989

9090
inc() ->
91-
couch_rand:uniform(16#ffd).
91+
rand:uniform(16#ffd).
9292

9393
state() ->
9494
AlgoStr = config:get("uuids", "algorithm", "sequential"),

src/couch/src/test_util.erl

+1-1
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ random_rev() ->
487487
couch_util:to_hex_bin(crypto:strong_rand_bytes(16)).
488488

489489
shuffle(List) ->
490-
Paired = [{couch_rand:uniform(), I} || I <- List],
490+
Paired = [{rand:uniform(), I} || I <- List],
491491
Sorted = lists:sort(Paired),
492492
[I || {_, I} <- Sorted].
493493

src/couch/test/eunit/couch_btree_tests.erl

+4-4
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ btree_open_test_() ->
8686

8787
sorted_kvs_test_() ->
8888
Funs = kvs_test_funs(),
89-
Sorted = [{Seq, couch_rand:uniform()} || Seq <- lists:seq(1, ?ROWS)],
89+
Sorted = [{Seq, rand:uniform()} || Seq <- lists:seq(1, ?ROWS)],
9090
{
9191
"BTree with sorted keys",
9292
{
@@ -103,7 +103,7 @@ sorted_kvs_test_() ->
103103
}.
104104

105105
rsorted_kvs_test_() ->
106-
Sorted = [{Seq, couch_rand:uniform()} || Seq <- lists:seq(1, ?ROWS)],
106+
Sorted = [{Seq, rand:uniform()} || Seq <- lists:seq(1, ?ROWS)],
107107
Funs = kvs_test_funs(),
108108
Reversed = Sorted,
109109
{
@@ -123,7 +123,7 @@ rsorted_kvs_test_() ->
123123

124124
shuffled_kvs_test_() ->
125125
Funs = kvs_test_funs(),
126-
Sorted = [{Seq, couch_rand:uniform()} || Seq <- lists:seq(1, ?ROWS)],
126+
Sorted = [{Seq, rand:uniform()} || Seq <- lists:seq(1, ?ROWS)],
127127
Shuffled = shuffle(Sorted),
128128
{
129129
"BTree with shuffled keys",
@@ -579,7 +579,7 @@ randomize(T, List) ->
579579
).
580580

581581
randomize(List) ->
582-
D = lists:map(fun(A) -> {couch_rand:uniform(), A} end, List),
582+
D = lists:map(fun(A) -> {rand:uniform(), A} end, List),
583583
{_, D1} = lists:unzip(lists:keysort(1, D)),
584584
D1.
585585

src/couch/test/eunit/couch_file_tests.erl

+3-3
Original file line numberDiff line numberDiff line change
@@ -340,14 +340,14 @@ check_header_recovery(CheckFun) ->
340340
ok.
341341

342342
write_random_data(Fd) ->
343-
write_random_data(Fd, 100 + couch_rand:uniform(1000)).
343+
write_random_data(Fd, 100 + rand:uniform(1000)).
344344

345345
write_random_data(Fd, 0) ->
346346
{ok, Bytes} = couch_file:bytes(Fd),
347347
{ok, (1 + Bytes div ?BLOCK_SIZE) * ?BLOCK_SIZE};
348348
write_random_data(Fd, N) ->
349349
Choices = [foo, bar, <<"bizzingle">>, "bank", ["rough", stuff]],
350-
Term = lists:nth(couch_rand:uniform(4) + 1, Choices),
350+
Term = lists:nth(rand:uniform(4) + 1, Choices),
351351
{ok, _, _} = couch_file:append_term(Fd, Term),
352352
write_random_data(Fd, N - 1).
353353

@@ -466,7 +466,7 @@ nuke_dir_test_() ->
466466
File0 = ?tempfile() ++ ".couch",
467467
RootDir = filename:dirname(File0),
468468
BaseName = filename:basename(File0),
469-
Seed = couch_rand:uniform(8999999999) + 999999999,
469+
Seed = rand:uniform(8999999999) + 999999999,
470470
DDocDir = io_lib:format("db.~b_design", [Seed]),
471471
ViewDir = filename:join([RootDir, DDocDir]),
472472
file:make_dir(ViewDir),

src/couch/test/eunit/couch_key_tree_tests.erl

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ should_find_missing_leaves_large_test() ->
360360
Seed = {1647, 841737, 351137},
361361
{_, Tree} = test_util:revtree_generate(1000, 0.2, 5, Seed),
362362
Seq = lists:seq(1, 1000),
363-
Revs1 = [{couch_rand:uniform(1000), test_util:random_rev()} || _ <- Seq],
363+
Revs1 = [{rand:uniform(1000), test_util:random_rev()} || _ <- Seq],
364364
Revs2 = couch_key_tree:find_missing(Tree, Revs1),
365365
?assertEqual(lists:sort(Revs1), lists:sort(Revs2))
366366
end).

src/couch/test/eunit/json_stream_parse_tests.erl

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ single_byte_data_fun([H | T]) ->
142142
multiple_bytes_data_fun([]) ->
143143
done;
144144
multiple_bytes_data_fun(L) ->
145-
N = couch_rand:uniform(7) - 1,
145+
N = rand:uniform(7) - 1,
146146
{Part, Rest} = split(L, N),
147147
{list_to_binary(Part), fun() -> multiple_bytes_data_fun(Rest) end}.
148148

src/couch_log/test/eunit/couch_log_test.erl

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,5 @@ check_levels(TestLevel, [CfgLevel | RestLevels]) ->
7272
check_levels(TestLevel, RestLevels).
7373

7474
new_msg() ->
75-
Bin = list_to_binary([couch_rand:uniform(255) || _ <- lists:seq(1, 16)]),
75+
Bin = list_to_binary([rand:uniform(255) || _ <- lists:seq(1, 16)]),
7676
couch_util:to_hex(Bin).

src/couch_replicator/src/couch_replicator_doc_processor.erl

+3-3
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ error_backoff(ErrCnt) ->
410410
% ErrCnt is the exponent here. The reason 64 is used is to start at
411411
% 64 (about a minute) max range. Then first backoff would be 30 sec
412412
% on average. Then 1 minute and so on.
413-
couch_rand:uniform(?INITIAL_BACKOFF_EXPONENT bsl Exp).
413+
rand:uniform(?INITIAL_BACKOFF_EXPONENT bsl Exp).
414414

415415
-spec filter_backoff() -> seconds().
416416
filter_backoff() ->
@@ -419,10 +419,10 @@ filter_backoff() ->
419419
% wait is longer, but not more than a day (?TS_DAY_SEC). If there are just
420420
% few, wait is shorter, starting at about 30 seconds. `2 *` is used since
421421
% the expected wait would then be 0.5 * Range so it is easier to see the
422-
% average wait. `1 +` is used because couch_rand:uniform only
422+
% average wait. `1 +` is used because rand:uniform only
423423
% accepts >= 1 values and crashes otherwise.
424424
Range = 1 + min(2 * (Total / 10), ?TS_DAY_SEC),
425-
?MIN_FILTER_DELAY_SEC + couch_rand:uniform(round(Range)).
425+
?MIN_FILTER_DELAY_SEC + rand:uniform(round(Range)).
426426

427427
% Replication was usurped - move it to the not_owner state
428428
% and try to kill running jobs if there are any.

src/couch_replicator/src/couch_replicator_docs.erl

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ update_rep_doc(RepDbName, RepDocId, KVs, Wait) when is_binary(RepDocId) ->
155155
throw:conflict ->
156156
Msg = "Conflict when updating replication doc `~s`. Retrying.",
157157
couch_log:error(Msg, [RepDocId]),
158-
ok = timer:sleep(couch_rand:uniform(erlang:min(128, Wait)) * 100),
158+
ok = timer:sleep(rand:uniform(erlang:min(128, Wait)) * 100),
159159
update_rep_doc(RepDbName, RepDocId, KVs, Wait * 2)
160160
end;
161161
update_rep_doc(RepDbName, #doc{body = {RepDocBody}} = RepDoc, KVs, _Try) ->

src/couch_replicator/src/couch_replicator_scheduler_job.erl

+1-1
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ startup_jitter() ->
520520
"startup_jitter",
521521
?STARTUP_JITTER_DEFAULT
522522
),
523-
couch_rand:uniform(erlang:max(1, Jitter)).
523+
rand:uniform(erlang:max(1, Jitter)).
524524

525525
headers_strip_creds([], Acc) ->
526526
lists:reverse(Acc);

src/ddoc_cache/test/eunit/ddoc_cache_lru_test.erl

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ recover(<<"pause", _/binary>>) ->
2828
end,
2929
{ok, paused};
3030
recover(<<"big", _/binary>>) ->
31-
{ok, [couch_rand:uniform() || _ <- lists:seq(1, 8192)]};
31+
{ok, [rand:uniform() || _ <- lists:seq(1, 8192)]};
3232
recover(DbName) ->
3333
{ok, DbName}.
3434

src/ioq/src/ioq.erl

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ make_next_request(#state{} = State) ->
207207
{false, true} ->
208208
choose_next_request(#state.background, State);
209209
{false, false} ->
210-
case couch_rand:uniform() < State#state.ratio of
210+
case rand:uniform() < State#state.ratio of
211211
true ->
212212
choose_next_request(#state.background, State);
213213
false ->

src/mem3/src/mem3.erl

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ choose_shards(DbName, Nodes, Options) ->
275275
mem3_util:create_partition_map(DbName, N, Q, RotatedNodes, Suffix).
276276

277277
rotate_rand(Nodes) ->
278-
{A, B} = lists:split(couch_rand:uniform(length(Nodes)), Nodes),
278+
{A, B} = lists:split(rand:uniform(length(Nodes)), Nodes),
279279
B ++ A.
280280

281281
get_placement(Options) ->

0 commit comments

Comments
 (0)