Ulf Moeller <[EMAIL PROTECTED]> in epsilon.openssl.dev:

>>   It is more convenient to have the range; also the previous
>>   prototype was misleading because max was larger than
>>   the actual maximum.)

> OK, so it would make sense to rename the variable in the prototype.
> But it is a frequent operation to generate a random number in [0..n-1]
> and [1..n-1] and the function should facilitate both.

BN_rand_range(min, max) (previous semantics) cannot be efficiently
implemented for the general case without using an additional temporary
variable range := max - min.  Only if 'min' is small, it makes sense
to evaluate  BN_rand_range(0, max)  repeatedly until the result
is >= min.

We could change BN_rand_range so that it always computes 'range' from
'min' and 'max'.  But this would mean unnecessary computational work
since often 'min' *is* small.

Alternatively, we could write an additional function for the special
case that 'min' is small or even for the special case min = 1.  Then
only this special function would include the 'r < min' loop.  But
since such loops can be easily implemented in the code that uses
BN_rand_range (just two lines, 'do' and 'while (...)'), I don't think
we need one more library function.
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
Development Mailing List                       [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to