Skip to content

Commit e9d93b2

Browse files
committed
compile out deprecated random module instead of runtime check
1 parent 3c4a0bc commit e9d93b2

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

rebar.config

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{xref_checks, [undefined_function_calls]}.
33
{erl_opts, [debug_info,
44
warnings_as_errors,
5-
{platform_define, "^[0-9]+", namespaced_types}]}.
5+
{platform_define, "^((1[8|9])|2)", rand_module}]}.
66
{cover_enabled, false}.
77
{eunit_opts, [verbose, {report,{eunit_surefire,[{dir,"."}]}}]}.
88
{edoc_opts, [{preprocess, true}]}.

src/rand_compat.erl

+24-20
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,34 @@
2626
uniform/0,
2727
uniform/1]).
2828

29+
-ifdef(rand_module).
2930
seed(SValue) ->
30-
case have_rand() of
31-
true -> rand:seed(exsplus, SValue);
32-
false -> (fun random:seed/1)(SValue)
33-
end.
31+
rand:seed(exsplus, SValue).
32+
-else.
33+
seed(SValue) ->
34+
random:seed(SValue).
35+
-endif.
3436

37+
-ifdef(rand_module).
38+
seed(A,B,C) ->
39+
rand:seed(exsplus, {A,B,C}).
40+
-else.
3541
seed(A,B,C) ->
36-
case have_rand() of
37-
true -> rand:seed(exsplus, {A,B,C});
38-
false -> (fun random:seed/3)(A,B,C)
39-
end.
42+
random:seed(A,B,C).
43+
-endif.
4044

45+
-ifdef(rand_module).
46+
uniform() ->
47+
rand:uniform().
48+
-else.
4149
uniform() ->
42-
case have_rand() of
43-
true -> rand:uniform();
44-
false -> (fun random:uniform/0)()
45-
end.
50+
random:uniform().
51+
-endif.
4652

53+
-ifdef(rand_module).
4754
uniform(N) ->
48-
case have_rand() of
49-
true -> rand:uniform(N);
50-
false -> (fun random:uniform/1)(N)
51-
end.
52-
53-
%% random module is deprecated since releases 19 (ERTS >= 8.0). It exists since release 18.
54-
have_rand() ->
55-
list_to_integer(erlang:system_info(otp_release)) > 17.
55+
rand:uniform(N).
56+
-else.
57+
uniform(N) ->
58+
random:uniform(N).
59+
-endif.

0 commit comments

Comments
 (0)