Skip to content

Commit 2735990

Browse files
committed
Use the new rand_compat module to transition from random to rand
References #860. [#122335241]
1 parent fa20bbc commit 2735990

8 files changed

+8
-17
lines changed

src/file_handle_cache.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,7 @@ notify_age(CStates, AverageAge) ->
14771477
notify_age0(Clients, CStates, Required) ->
14781478
case [CState || CState <- CStates, CState#cstate.callback =/= undefined] of
14791479
[] -> ok;
1480-
Notifications -> S = random:uniform(length(Notifications)),
1480+
Notifications -> S = rand_compat:uniform(length(Notifications)),
14811481
{L1, L2} = lists:split(S, Notifications),
14821482
notify(Clients, Required, L2 ++ L1)
14831483
end.

src/gm.erl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -536,9 +536,6 @@ forget_group(GroupName) ->
536536

537537
init([GroupName, Module, Args, TxnFun]) ->
538538
put(process_name, {?MODULE, GroupName}),
539-
_ = random:seed(erlang:phash2([node()]),
540-
time_compat:monotonic_time(),
541-
time_compat:unique_integer()),
542539
Self = make_member(GroupName),
543540
gen_server2:cast(self(), join),
544541
{ok, #state { self = Self,
@@ -1069,7 +1066,7 @@ join_group(Self, GroupName, #gm_group { members = Members } = Group, TxnFun) ->
10691066
prune_or_create_group(Self, GroupName, TxnFun),
10701067
TxnFun);
10711068
Alive ->
1072-
Left = lists:nth(random:uniform(length(Alive)), Alive),
1069+
Left = lists:nth(rand_compat:uniform(length(Alive)), Alive),
10731070
Handler =
10741071
fun () ->
10751072
join_group(

src/rabbit_cli.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ main(ParseFun, DoFun, UsageMod) ->
147147
start_distribution_anon(0, LastError) ->
148148
{error, LastError};
149149
start_distribution_anon(TriesLeft, _) ->
150-
NameCandidate = list_to_atom(rabbit_misc:format("rabbitmq-cli-~2..0b", [rabbit_misc:random(100)])),
150+
NameCandidate = list_to_atom(rabbit_misc:format("rabbitmq-cli-~2..0b", [rand_compat:uniform(100)])),
151151
case net_kernel:start([NameCandidate, name_type()]) of
152152
{ok, _} = Result ->
153153
Result;

src/rabbit_limiter.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ notify_queues(State = #lim{ch_pid = ChPid, queues = Queues}) ->
432432
%% We randomly vary the position of queues in the list,
433433
%% thus ensuring that each queue has an equal chance of
434434
%% being notified first.
435-
{L1, L2} = lists:split(random:uniform(L), QList),
435+
{L1, L2} = lists:split(rand_compat:uniform(L), QList),
436436
[[ok = rabbit_amqqueue:resume(Q, ChPid) || Q <- L3]
437437
|| L3 <- [L2, L1]],
438438
ok

src/rabbit_mirror_queue_mode_exactly.erl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ suggested_queue_nodes(Count, MNode, SNodes, _SSNodes, Poss) ->
4545
end}.
4646

4747
shuffle(L) ->
48-
random:seed(erlang:phash2([node()]),
49-
time_compat:monotonic_time(),
50-
time_compat:unique_integer()),
51-
{_, L1} = lists:unzip(lists:keysort(1, [{random:uniform(), N} || N <- L])),
48+
{_, L1} = lists:unzip(lists:keysort(1, [{rand_compat:uniform(), N} || N <- L])),
5249
L1.
5350

5451
validate_policy(N) when is_integer(N) andalso N > 0 ->

src/rabbit_password.erl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ hash(HashingMod, Cleartext) ->
3535
<<SaltBin/binary, Hash/binary>>.
3636

3737
generate_salt() ->
38-
random:seed(erlang:phash2([node()]),
39-
time_compat:monotonic_time(),
40-
time_compat:unique_integer()),
41-
Salt = random:uniform(16#ffffffff),
38+
Salt = rand_compat:uniform(16#ffffffff),
4239
<<Salt:32>>.
4340

4441
salted_hash(Salt, Cleartext) ->

test/priority_queue_SUITE.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ publish_payload(Ch, Q, PPds) ->
546546
amqp_channel:wait_for_confirms(Ch).
547547

548548
publish_many(_Ch, _Q, 0) -> ok;
549-
publish_many( Ch, Q, N) -> publish1(Ch, Q, random:uniform(5)),
549+
publish_many( Ch, Q, N) -> publish1(Ch, Q, rand_compat:uniform(5)),
550550
publish_many(Ch, Q, N - 1).
551551

552552
publish1(Ch, Q, P) ->

test/unit_inbroker_SUITE.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,7 @@ maybe_switch_queue_mode(VQ) ->
13161316

13171317
random_queue_mode() ->
13181318
Modes = [lazy, default],
1319-
lists:nth(random:uniform(length(Modes)), Modes).
1319+
lists:nth(rand_compat:uniform(length(Modes)), Modes).
13201320

13211321
pub_res({_, VQS}) ->
13221322
VQS;

0 commit comments

Comments
 (0)