You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2017/10/02 19:18:07 UTC
[1/2] couchdb-khash git commit: Replace deprecated random module
Repository: couchdb-khash
Updated Branches:
refs/heads/master 7c6a9cd97 -> 0ca7f7e19
Replace deprecated random module
Replaced with crypto:rand_uniform functions.
Also updated .travis.yml to the default set of Erlang releases.
Project: http://git-wip-us.apache.org/repos/asf/couchdb-khash/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-khash/commit/0f3995b9
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-khash/tree/0f3995b9
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-khash/diff/0f3995b9
Branch: refs/heads/master
Commit: 0f3995b93f670a244e4c61798ce0ec02059f9661
Parents: 7c6a9cd
Author: Nick Vatamaniuc <va...@apache.org>
Authored: Mon Oct 2 14:51:32 2017 -0400
Committer: Nick Vatamaniuc <va...@apache.org>
Committed: Mon Oct 2 15:00:07 2017 -0400
----------------------------------------------------------------------
.travis.yml | 8 +++-----
test/gen_term.erl | 37 +++++++++++++++++++++++--------------
test/khash_test.erl | 14 +++++++++++---
3 files changed, 37 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-khash/blob/0f3995b9/.travis.yml
----------------------------------------------------------------------
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
+
http://git-wip-us.apache.org/repos/asf/couchdb-khash/blob/0f3995b9/test/gen_term.erl
----------------------------------------------------------------------
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_atom(MaxSize) ->
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_reference(_) ->
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_tuple(MaxSize) ->
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_bitstring(MaxSize) ->
gen_bignum(_) ->
- 16#FFFFFFFFFFFFFFFF + random:uniform(16#FFFFFFFF).
+ 16#FFFFFFFFFFFFFFFF + random_uniform(16#FFFFFFFF).
gen_function(_) ->
@@ -107,7 +107,7 @@ gen_function(_) ->
choice(Options) ->
- lists:nth(random:uniform(length(Options)), Options).
+ lists:nth(random_uniform(length(Options)), Options).
value_types() ->
@@ -129,3 +129,12 @@ value_types() ->
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).
http://git-wip-us.apache.org/repos/asf/couchdb-khash/blob/0f3995b9/test/khash_test.erl
----------------------------------------------------------------------
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 @@ randomized_test_() ->
{setup,
local,
fun() ->
- random:seed(erlang:now()),
Dict = dict:new(),
{ok, KHash} = khash:new(),
Actions = [
@@ -367,7 +366,7 @@ run_to_list({D, H}) ->
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 @@ weighted_choice([{_, I} | _], _, _) ->
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).
[2/2] couchdb-khash git commit: Merge branch
'replace-deprecated-random-module'
Posted by va...@apache.org.
Merge branch 'replace-deprecated-random-module'
Fixes #7
Project: http://git-wip-us.apache.org/repos/asf/couchdb-khash/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-khash/commit/0ca7f7e1
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-khash/tree/0ca7f7e1
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-khash/diff/0ca7f7e1
Branch: refs/heads/master
Commit: 0ca7f7e196bf9f62c2860dbe17a405d53a0120f0
Parents: 7c6a9cd 0f3995b
Author: Nick Vatamaniuc <va...@apache.org>
Authored: Mon Oct 2 15:17:43 2017 -0400
Committer: Nick Vatamaniuc <va...@apache.org>
Committed: Mon Oct 2 15:17:43 2017 -0400
----------------------------------------------------------------------
.travis.yml | 8 +++-----
test/gen_term.erl | 37 +++++++++++++++++++++++--------------
test/khash_test.erl | 14 +++++++++++---
3 files changed, 37 insertions(+), 22 deletions(-)
----------------------------------------------------------------------