class method
OpenSSL::BN.rand_range
(untyped) -> untyped
BN.rand_range(range) → aBN
ext/openssl/ossl_bn.c
View on GitHub ↗
static VALUE
ossl_bn_s_rand_range(VALUE klass, VALUE range)
{
BIGNUM *bn = GetBNPtr(range), *result;
VALUE obj = NewBN(klass);
if (!(result = BN_new()))
ossl_raise(eBNError, "BN_new");
if (BN_rand_range(result, bn) <= 0) {
BN_free(result);
ossl_raise(eBNError, "BN_rand_range");
}
SetBN(obj, result);
return obj;
}
Generates a cryptographically strong pseudo-random number in the range 0…range.
See also the man page BN_rand_range(3).