diff options
author | Sverker Eriksson <[email protected]> | 2011-09-19 11:11:46 +0200 |
---|---|---|
committer | Sverker Eriksson <[email protected]> | 2011-09-19 11:11:46 +0200 |
commit | 50dc9c82f71cc85ca88ba40d022b1ada941448f5 (patch) | |
tree | 49696d79941805346de1989703550e303a63a493 /lib/crypto/src/crypto.erl | |
parent | 40f724a33dae5e7670a710e32abe3493d660ea46 (diff) | |
parent | 307c06863caebcd63f98c010a31a0263890af9b4 (diff) | |
download | otp-50dc9c82f71cc85ca88ba40d022b1ada941448f5.tar.gz otp-50dc9c82f71cc85ca88ba40d022b1ada941448f5.tar.bz2 otp-50dc9c82f71cc85ca88ba40d022b1ada941448f5.zip |
Merge branch 'dev' into major
Diffstat (limited to 'lib/crypto/src/crypto.erl')
-rw-r--r-- | lib/crypto/src/crypto.erl | 11 |
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. |