{if_var_true, elixir, {d, 'ELIXIR_ENABLED'}},
{if_var_true, erlang_deprecated_types, {d, 'ERL_DEPRECATED_TYPES'}},
{if_have_fun, {crypto, strong_rand_bytes, 1}, {d, 'STRONG_RAND_BYTES'}},
+ {if_have_fun, {rand, uniform, 1}, {d, 'RAND_UNIFORM'}},
{if_have_fun, {gb_sets, iterator_from, 2}, {d, 'GB_SETS_ITERATOR_FROM'}},
{if_have_fun, {public_key, short_name_hash, 1}, {d, 'SHORT_NAME_HASH'}},
{if_var_true, hipe, native},
-spec get_delay() -> non_neg_integer().
get_delay() ->
MaxDelay = ejabberd_config:get_option(s2s_max_retry_delay, 300),
- crypto:rand_uniform(1, MaxDelay).
+ randoms:uniform(MaxDelay).
-spec set_idle_timeout(state()) -> state().
set_idle_timeout(#{on_route := send, server := LServer} = State) ->
-spec make_rand_char() -> char().
make_rand_char() ->
- map_int_to_char(crypto:rand_uniform(0, 62)).
+ map_int_to_char(randoms:uniform(0, 61)).
-spec map_int_to_char(0..61) -> char().
-define(THRESHOLD, 16#10000000000000000).
+-ifdef(RAND_UNIFORM).
+get_string() ->
+ R = rand:uniform(?THRESHOLD),
+ integer_to_binary(R).
+
+uniform() ->
+ rand:uniform().
+
+uniform(N) ->
+ rand:uniform(N).
+
+uniform(N, M) ->
+ rand:uniform(M-N+1) + N-1.
+-else.
get_string() ->
R = crypto:rand_uniform(0, ?THRESHOLD),
integer_to_binary(R).
uniform(N, M) ->
crypto:rand_uniform(N, M+1).
+-endif.
-ifdef(STRONG_RAND_BYTES).
bytes(N) ->