[erlang-questions] Bug using negative numbers to crypto:rand_uniform?

Jesper Louis Andersen <>
Tue Jul 8 17:19:44 CEST 2008


Hi,


I've tried the following in R11B-5 and had people check it in R12B
(subrevision unknown) as well:

Calls of the form

crypto:rand_uniform(Lo, Hi).

Where Lo and Hi are negative integers fail due to some wrap-around somewhere:

()12> crypto:rand_uniform(-10, -5).
250

The documentation states:

rand_uniform(Lo, Hi) -> N

Types:
Lo, Hi, N = Mpint | integer()
Mpint = binary()

Generate  a  random  number  N, Lo =< N < Hi. Uses the crypto library
pseudo-random number generator. The arguments (and result)  can  be
either  erlang  integers  or binary multi-precision integers.

---

Which doesn't mention anything about negative integer() values. Other
interesting test cases are combinations of negative and positive
numbers and where Lo > Hi etc. It is rather easy to work around, but
either the documentation or the implementation should be changed to
solve the problem in my humble opinion.

Finally: Should this go to erlang-bugs@ intead? Or is that I just
can't read the documentation?



More information about the erlang-questions mailing list