Skip to content

Commit 4b4e1e8

Browse files
authored
Merge pull request #414 from ariel-anieli/deprecation-random
Replaced calls to `random` by `rand`
2 parents 374a733 + 0b35269 commit 4b4e1e8

File tree

13 files changed

+31
-31
lines changed

13 files changed

+31
-31
lines changed

src/lib/uuid.erl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ random_str() ->
5353
%%
5454
random() ->
5555
U = <<
56-
(random:uniform(4294967296) - 1):32,
57-
(random:uniform(4294967296) - 1):32,
58-
(random:uniform(4294967296) - 1):32,
59-
(random:uniform(4294967296) - 1):32
56+
(rand:uniform(4294967296) - 1):32,
57+
(rand:uniform(4294967296) - 1):32,
58+
(rand:uniform(4294967296) - 1):32,
59+
(rand:uniform(4294967296) - 1):32
6060
>>,
6161
format_uuid(U, 4).
6262

@@ -66,7 +66,7 @@ random() ->
6666
%%
6767
srandom() ->
6868
{A1,A2,A3} = erlang:now(),
69-
random:seed(A1, A2, A3),
69+
rand:seed(A1, A2, A3),
7070
random().
7171

7272
%% @spec sha(Namespace, Name) -> uuid()
@@ -150,10 +150,10 @@ stop() ->
150150

151151
init(Options) ->
152152
{A1,A2,A3} = proplists:get_value(seed, Options, erlang:now()),
153-
random:seed(A1, A2, A3),
153+
rand:seed(A1, A2, A3),
154154
State = #state{
155155
node = proplists:get_value(node, Options, <<0:48>>),
156-
clock_seq = random:uniform(65536)
156+
clock_seq = rand:uniform(65536)
157157
},
158158
error_logger:info_report("uuid server started"),
159159
{ok, State}.

src/lib/websocket.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ decode(Data) ->
131131
%%% Internal functions
132132
%%%===================================================================
133133
gen_accept_key() ->
134-
random:seed(erlang:now()),
134+
rand:seed(erlang:now()),
135135
Key = crypto:strong_rand_bytes(16),
136136
KeyStr = base64:encode_to_string(Key),
137137
Accept = binary:list_to_bin(KeyStr ++ "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"),

src/test/ts_test_config.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ config_thinktime2_test() ->
122122
receive
123123
{timeout,Ref2,end_thinktime} -> ok
124124
end,
125-
random:seed(), % reinit seed for others tests
125+
rand:seed(), % reinit seed for others tests
126126
?assertMatch({random,1000}, Req).
127127

128128
read_config_tag_noexclusion_test() ->

src/tsung/ts_bosh.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ do_receive_http_response(State, Socket, Vsn) ->
276276

277277
do_connect(#state{type = Type, host = Host, path = Path, parent_pid = ParentPid} = State, Domain) ->
278278
?DebugF("do_connect ~p",[State]),
279-
Rid = 1000 + random:uniform(100000),
279+
Rid = 1000 + rand:uniform(100000),
280280
%%Port= proplists:get_value(local_port, Options, undefined),
281281
NewState = State#state{
282282
domain = Domain,

src/tsung/ts_cport.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ init([]) ->
7777
{Min, Max} = {?config(cport_min),?config(cport_max)},
7878
ts_utils:init_seed(),
7979
%% set random port for the initial value.
80-
case catch Min+random:uniform(Max-Min) of
80+
case catch Min+rand:uniform(Max-Min) of
8181
Val when is_integer(Val) ->
8282
?LOGF("Ok, starting with ~p value~n",[Val],?NOTICE),
8383
{ok, #state{min_port=Min, max_port=Max}};

src/tsung/ts_launcher.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ launcher(timeout, State=#launcher{nusers = Users,
224224
end;
225225
error ->
226226
% retry with the next user, wait randomly a few msec
227-
RndWait = random:uniform(?NEXT_AFTER_FAILED_TIMEOUT),
227+
RndWait = rand:uniform(?NEXT_AFTER_FAILED_TIMEOUT),
228228
{next_state,launcher,State#launcher{nusers = Users-1} , RndWait}
229229
end.
230230

src/tsung/ts_session_cache.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ code_change(_OldVsn, State, _Extra) ->
197197
choose_user_agent(empty) -> {ok, "tsung"};
198198
choose_user_agent([{_P, Val}]) -> {ok, Val};
199199
choose_user_agent(UserAgents) ->
200-
choose_user_agent(UserAgents, random:uniform(100),0).
200+
choose_user_agent(UserAgents, rand:uniform(100),0).
201201

202202
choose_user_agent([{P, Val} | _],Rand, Cur) when Rand =< P+Cur->
203203
{ok, Val};

src/tsung/ts_stats.erl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,19 @@ sample (F, X, Param, N) ->
5555
sample(F, [F(Param)|X], Param, N-1 ).
5656

5757
uniform(Min,Max)->
58-
Min+random:uniform(Max-Min+1)-1.
58+
Min+rand:uniform(Max-Min+1)-1.
5959

6060
%% random sample from an exponential distribution
6161
exponential(Param) ->
62-
-math:log(random:uniform())/Param.
62+
-math:log(rand:uniform())/Param.
6363

6464
%% N samples from an exponential distribution
6565
exponential(Param, N) ->
6666
sample(fun(X) -> exponential(X) end , Param, N).
6767

6868
%% random sample from a Pareto distribution
6969
pareto(#pareto{a=A, beta=Beta}) ->
70-
A/(math:pow(random:uniform(), 1/Beta)).
70+
A/(math:pow(rand:uniform(), 1/Beta)).
7171

7272
%% if a list is given, construct a record for the parameters
7373
pareto([A, Beta], N) ->
@@ -86,7 +86,7 @@ invgaussian(Param,N) ->
8686
invgaussian(#invgaussian{mu=Mu, lambda=Lambda}) ->
8787
Y = Mu*pow(normal(), 2),
8888
X1 = Mu+Mu*Y/(2*Lambda)-Mu*sqrt(4*Lambda*Y+pow(Y,2))/(2*Lambda),
89-
U = random:uniform(),
89+
U = rand:uniform(),
9090
X = (Mu/(Mu+X1))-U,
9191
case X >=0 of
9292
true -> X1;
@@ -114,8 +114,8 @@ normal_boxm(M,S,X1,_X2,W) when W < 1->
114114
Y1 = X1 * W2,
115115
M + Y1 * S;
116116
normal_boxm(M,S,_,_,_W) ->
117-
X1 = 2.0 * random:uniform() - 1.0,
118-
X2 = 2.0 * random:uniform() - 1.0,
117+
X1 = 2.0 * rand:uniform() - 1.0,
118+
X2 = 2.0 * rand:uniform() - 1.0,
119119
normal_boxm(M,S,X1,X2,X1 * X1 + X2 * X2).
120120
%%%
121121

src/tsung/ts_utils.erl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ init_seed(A) when is_integer(A)->
162162
%% node to set a reproductible but different seed for each launcher.
163163
Id=get_node_id(),
164164
?DebugF("Seeding with ~p on node ~p~n",[Id,node()]),
165-
random:seed(1000*Id,-1000*A*Id,1000*A*A);
165+
rand:seed(1000*Id,-1000*A*Id,1000*A*A);
166166
init_seed({A,B}) when is_integer(A) and is_integer(B)->
167167
Id=get_node_id(),
168168
?DebugF("Seeding with ~p ~p ~p on node ~p~n",[A,B,Id,node()]),
@@ -171,9 +171,9 @@ init_seed({A,B}) when is_integer(A) and is_integer(B)->
171171
%% initial pseudo random values will be quite closed to each
172172
%% other. Trying to avoid this by using a multiplier big enough
173173
%% (because the algorithm use mod 30XXX , see random.erl).
174-
random:seed(4000*A*B*Id,-4000*B*A*Id,4000*Id*Id*A);
174+
rand:seed(4000*A*B*Id,-4000*B*A*Id,4000*Id*Id*A);
175175
init_seed({A,B,C}) ->
176-
random:seed(A,B,C).
176+
rand:seed(A,B,C).
177177

178178
get_node_id() ->
179179
case string:tokens(atom_to_list(node()),"@") of
@@ -762,12 +762,12 @@ urandomstr(Size) when is_integer(Size), Size >= 0 ->
762762
%% @end
763763
%%----------------------------------------------------------------------
764764
randomstr(Size) when is_integer(Size), Size >= 0 ->
765-
lists:map(fun (_) -> random:uniform(25) + $a end, lists:seq(1,Size)).
765+
lists:map(fun (_) -> rand:uniform(25) + $a end, lists:seq(1,Size)).
766766

767767
random_alphanumstr(Size) when is_integer(Size), Size >= 0 ->
768768
AllowedChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
769769
S = length(AllowedChars),
770-
lists:map(fun (_) -> lists:nth(random:uniform(S), AllowedChars) end, lists:seq(1,Size)).
770+
lists:map(fun (_) -> lists:nth(rand:uniform(S), AllowedChars) end, lists:seq(1,Size)).
771771

772772
%%----------------------------------------------------------------------
773773
%% @spec randombinstr(Size::integer()) ->binary()
@@ -779,7 +779,7 @@ randombinstr(Size) when is_integer(Size), Size > 0 ->
779779
randombinstr(Size,<<>>).
780780
randombinstr(0,Bin) -> Bin;
781781
randombinstr(Size,Bin) ->
782-
C=random:uniform(25)+$a,
782+
C=rand:uniform(25)+$a,
783783
randombinstr(Size-1, << Bin/binary, C >>).
784784

785785

src/tsung_controller/ts_config_server.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ choose_client_ip(#client{iprange = {A,B,C,D}}) ->
600600
choose_server([Server], _TotalWeight) ->
601601
{ok, Server};
602602
choose_server(Servers, Total) ->
603-
choose_server(Servers, random:uniform() * Total, 0).
603+
choose_server(Servers, rand:uniform() * Total, 0).
604604

605605
choose_server([S=#server{weight=P} | _],Rand,Cur) when Rand =< P+Cur->
606606
{ok, S};
@@ -637,9 +637,9 @@ choose_rr(List, Key, _) ->
637637
choose_session([Session], _Total, _PhaseId) -> %% only one Session
638638
{ok, Session};
639639
choose_session(Sessions,Total,PhaseId) when is_number(Total)->
640-
choose_session(Sessions, random:uniform() * Total, 0, PhaseId);
640+
choose_session(Sessions, rand:uniform() * Total, 0, PhaseId);
641641
choose_session(Sessions,Total,PhaseId) when is_list(Total) ->
642-
choose_session(Sessions, random:uniform() * lists:nth(PhaseId, Total), 0, PhaseId).
642+
choose_session(Sessions, rand:uniform() * lists:nth(PhaseId, Total), 0, PhaseId).
643643

644644
choose_session([S=#session{popularity=P} | _],Rand,Cur,_PhaseId) when is_number(P) andalso Rand =< P+Cur->
645645
{ok, S};

0 commit comments

Comments
 (0)