Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
class method
OpenSSL::Random.random_bytes
random_bytes(length) → string
ext/openssl/ossl_rand.c
View on GitHub ↗
static VALUE
ossl_rand_bytes(VALUE self, VALUE len)
{
VALUE str;
int n = NUM2INT(len);
int ret;
str = rb_str_new(0, n);
ret = RAND_bytes((unsigned char *)RSTRING_PTR(str), n);
if (ret == 0) {
ossl_raise(eRandomError, "RAND_bytes");
} else if (ret == -1) {
ossl_raise(eRandomError, "RAND_bytes is not supported");
}
return str;
}