APIdock / Ruby
/
method

pseudo_bytes

ruby latest stable - Class: OpenSSL ::Random
pseudo_bytes(p1)
public

Generates a String with length number of pseudo-random bytes.

Pseudo-random byte sequences generated by ::pseudo_bytes will be unique if they are of sufficient length, but are not necessarily unpredictable.

Example

OpenSSL ::Random .pseudo_bytes (12)
#=> "..."
static VALUE
ossl_rand_pseudo_bytes(VALUE self, VALUE len)
{
 VALUE str;
 int n = NUM2INT(len);
 str = rb_str_new(0, n);
 if (RAND_pseudo_bytes((unsigned char *)RSTRING_PTR(str), n) < 1) {
 ossl_raise(eRandomError, NULL);
 }
 return str;
}

AltStyle によって変換されたページ (->オリジナル) /