aboutsummaryrefslogtreecommitdiffstats
path: root/lib/crypto/src/crypto.erl
diff options
context:
space:
mode:
authorMicael Karlberg <[email protected]>2011-09-19 19:26:54 +0200
committerMicael Karlberg <[email protected]>2011-09-19 19:26:54 +0200
commit7c730a573a7e239f41bc619b024a675667767428 (patch)
tree1265ca1ddae47b094af21f669d0526c9c1b074dd /lib/crypto/src/crypto.erl
parent13fcdd5c954ddbb8ac9401d73f8e77423fbd976c (diff)
parente84f232326b2800ca806c867b2bfbe3652d423cb (diff)
downloadotp-7c730a573a7e239f41bc619b024a675667767428.tar.gz
otp-7c730a573a7e239f41bc619b024a675667767428.tar.bz2
otp-7c730a573a7e239f41bc619b024a675667767428.zip
Merge branch 'dev' of super:otp into bmk/inets/inets571_integration
Diffstat (limited to 'lib/crypto/src/crypto.erl')
-rw-r--r--lib/crypto/src/crypto.erl11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/crypto/src/crypto.erl b/lib/crypto/src/crypto.erl
index c35dfcebab..c3e13d6b91 100644
--- a/lib/crypto/src/crypto.erl
+++ b/lib/crypto/src/crypto.erl
@@ -415,6 +415,13 @@ rand_uniform(From,To) when is_binary(From), is_binary(To) ->
Whatever
end;
rand_uniform(From,To) when is_integer(From),is_integer(To) ->
+ if From < 0 ->
+ rand_uniform_pos(0, To - From) + From;
+ true ->
+ rand_uniform_pos(From, To)
+ end.
+
+rand_uniform_pos(From,To) when From < To ->
BinFrom = mpint(From),
BinTo = mpint(To),
case rand_uniform(BinFrom, BinTo) of
@@ -422,7 +429,9 @@ rand_uniform(From,To) when is_integer(From),is_integer(To) ->
erlint(Result);
Other ->
Other
- end.
+ end;
+rand_uniform_pos(_,_) ->
+ error(badarg).
rand_uniform_nif(_From,_To) -> ?nif_stub.