aboutsummaryrefslogtreecommitdiffstats
path: root/lib/crypto/test/crypto_SUITE.erl
diff options
context:
space:
mode:
authorGuilherme Andrade <[email protected]>2017-03-18 12:57:19 +0000
committerGuilherme Andrade <[email protected]>2017-03-18 13:03:41 +0000
commite50f63fbb2c974b4b8ad50095ca0b16a846fc161 (patch)
treeb1bc8bc0c335ab4eff625843c49f1d89479de7cb /lib/crypto/test/crypto_SUITE.erl
parentd07008a0562d1f83dcab144fdec9fd920deb2b96 (diff)
downloadotp-e50f63fbb2c974b4b8ad50095ca0b16a846fc161.tar.gz
otp-e50f63fbb2c974b4b8ad50095ca0b16a846fc161.tar.bz2
otp-e50f63fbb2c974b4b8ad50095ca0b16a846fc161.zip
Restyle crypto strong numeric generators
for usage in rand
Diffstat (limited to 'lib/crypto/test/crypto_SUITE.erl')
-rw-r--r--lib/crypto/test/crypto_SUITE.erl46
1 files changed, 23 insertions, 23 deletions
diff --git a/lib/crypto/test/crypto_SUITE.erl b/lib/crypto/test/crypto_SUITE.erl
index 6e3a3879c4..0d80786fbc 100644
--- a/lib/crypto/test/crypto_SUITE.erl
+++ b/lib/crypto/test/crypto_SUITE.erl
@@ -37,8 +37,8 @@ all() ->
mod_pow,
exor,
rand_uniform,
- strong_rand_uniform_float,
- strong_rand_uniform_integer
+ strong_rand_range,
+ strong_rand_float
].
groups() ->
@@ -488,43 +488,43 @@ rand_uniform(Config) when is_list(Config) ->
10 = byte_size(crypto:strong_rand_bytes(10)).
%%--------------------------------------------------------------------
-strong_rand_uniform_float() ->
- [{doc, "strong_rand_uniform float testing"}].
-strong_rand_uniform_float(Config) when is_list(Config) ->
- Samples = [crypto:strong_rand_uniform() || _ <- lists:seq(1, 10000)],
- allmap(
- fun (V) ->
- (V >= 0.0 andalso V < 1.0)
- orelse {false, ct:fail({"Not in interval", V, 0.0, 1.0})}
- end,
- Samples).
-
-strong_rand_uniform_integer() ->
- [{doc, "strong_rand_uniform integer testing"}].
-strong_rand_uniform_integer(Config) when is_list(Config) ->
+strong_rand_range() ->
+ [{doc, "strong_rand_range testing"}].
+strong_rand_range(Config) when is_list(Config) ->
MaxCeiling = 1 bsl 32,
- Ceilings = [1 | % edge case where the ceiling equals the floor
- [crypto:strong_rand_uniform(MaxCeiling)
+ Ceilings = [1 | % edge case where only 0 can be generated
+ [binary:decode_unsigned(crypto:strong_rand_range(MaxCeiling), big)
|| _ <- lists:seq(1, 99)]],
allmap(
fun (Ceiling) ->
- case Ceiling >= 1 andalso Ceiling =< MaxCeiling of
+ case Ceiling >= 0 andalso Ceiling < MaxCeiling of
false ->
- {false, ct:fail({"Ceiling not in interval", Ceiling, 1, MaxCeiling})};
+ {false, ct:fail({"Ceiling not in interval", Ceiling, 0, MaxCeiling})};
true ->
- Samples = [crypto:strong_rand_uniform(Ceiling)
+ Samples = [binary:decode_unsigned(crypto:strong_rand_range(Ceiling), big)
|| _ <- lists:seq(1, 100)],
allmap(
fun (V) ->
- (V >= 1 andalso V =< Ceiling)
- orelse {false, ct:fail({"Sample not in interval", V, 1, Ceiling})}
+ (V >= 0 andalso V < Ceiling)
+ orelse {false, ct:fail({"Sample not in interval", V, 0, Ceiling})}
end,
Samples)
end
end,
Ceilings).
+strong_rand_float() ->
+ [{doc, "strong_rand_float testing"}].
+strong_rand_float(Config) when is_list(Config) ->
+ Samples = [crypto:strong_rand_float() || _ <- lists:seq(1, 10000)],
+ allmap(
+ fun (V) ->
+ (V >= 0.0 andalso V < 1.0)
+ orelse {false, ct:fail({"Not in interval", V, 0.0, 1.0})}
+ end,
+ Samples).
+
%%--------------------------------------------------------------------
%% Internal functions ------------------------------------------------
%%--------------------------------------------------------------------