Merge branch 'replace-deprecated-random-module'
Fixes #7
diff --git a/.travis.yml b/.travis.yml
index 99e6cb3..3a637c2 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,10 +1,8 @@
language: erlang
otp_release:
+ - 19.3
+ - 18.3
- 17.5
- - 17.4
- - 17.1
- - 17.0
- R16B03-1
- - R14B04
- - R14B02
+
diff --git a/test/gen_term.erl b/test/gen_term.erl
index 11a4f96..bf5acb6 100644
--- a/test/gen_term.erl
+++ b/test/gen_term.erl
@@ -42,18 +42,18 @@
gen_integer(_) ->
- Value = case random:uniform() < 0.5 of
- true -> random:uniform(127);
- false -> random:uniform(16#FFFFFFFF)
+ Value = case random_uniform() < 0.5 of
+ true -> random_uniform(127);
+ false -> random_uniform(16#FFFFFFFF)
end,
- case random:uniform() < 0.5 of
+ case random_uniform() < 0.5 of
true -> -1 * Value;
false -> Value
end.
gen_float(_) ->
- random:uniform() * float(16#FFFFFFFF).
+ random_uniform() * float(16#FFFFFFFF).
gen_reference(_) ->
@@ -62,12 +62,12 @@
gen_port(_) ->
Ports = erlang:ports(),
- lists:nth(random:uniform(length(Ports)), Ports).
+ lists:nth(random_uniform(length(Ports)), Ports).
gen_pid(_) ->
Pids = erlang:processes(),
- lists:nth(random:uniform(length(Pids)), Pids).
+ lists:nth(random_uniform(length(Pids)), Pids).
gen_tuple(MaxSize) ->
@@ -75,18 +75,18 @@
gen_list(MaxSize) ->
- Width = random:uniform(MaxSize),
+ Width = random_uniform(MaxSize),
[any(MaxSize-Width) || _ <- lists:seq(1, Width)].
gen_short_string(_) ->
- Size = random:uniform(255),
- [random:uniform(127) || _ <- lists:seq(1, Size)].
+ Size = random_uniform(255),
+ [random_uniform(127) || _ <- lists:seq(1, Size)].
gen_string(_) ->
- Size = random:uniform(4096),
- [random:uniform(127) || _ <- lists:seq(1, Size)].
+ Size = random_uniform(4096),
+ [random_uniform(127) || _ <- lists:seq(1, Size)].
gen_binary(MaxSize) ->
@@ -99,7 +99,7 @@
gen_bignum(_) ->
- 16#FFFFFFFFFFFFFFFF + random:uniform(16#FFFFFFFF).
+ 16#FFFFFFFFFFFFFFFF + random_uniform(16#FFFFFFFF).
gen_function(_) ->
@@ -107,7 +107,7 @@
choice(Options) ->
- lists:nth(random:uniform(length(Options)), Options).
+ lists:nth(random_uniform(length(Options)), Options).
value_types() ->
@@ -129,3 +129,12 @@
all_types() ->
value_types() ++ [gen_tuple, gen_list].
+
+
+random_uniform() ->
+ Range = 1 bsl 32,
+ crypto:rand_uniform(0, Range) / Range.
+
+
+random_uniform(N) ->
+ crypto:rand_uniform(1, N + 1).
diff --git a/test/khash_test.erl b/test/khash_test.erl
index cc7a429..20bd785 100644
--- a/test/khash_test.erl
+++ b/test/khash_test.erl
@@ -83,7 +83,6 @@
{setup,
local,
fun() ->
- random:seed(erlang:now()),
Dict = dict:new(),
{ok, KHash} = khash:new(),
Actions = [
@@ -367,7 +366,7 @@
weighted_choice(Items0) ->
Items = lists:sort(Items0),
Sum = lists:sum([W || {W, _} <- Items]),
- Choice = random:uniform() * Sum,
+ Choice = random_uniform() * Sum,
weighted_choice(Items, 0.0, Choice).
weighted_choice([], _, _) ->
@@ -379,7 +378,16 @@
random_key(D) ->
Keys = lists:usort(dict:fetch_keys(D) ++ [foo]),
- lists:nth(random:uniform(length(Keys)), Keys).
+ lists:nth(random_uniform(length(Keys)), Keys).
random_val() ->
gen_term:any().
+
+
+random_uniform() ->
+ Range = 1 bsl 32,
+ crypto:rand_uniform(0, Range) / Range.
+
+
+random_uniform(N) ->
+ crypto:rand_uniform(1, N + 1).