Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
class method
OpenSSL::Random.random_add
(::String str, ::Numeric entropy) -> self
add(str, entropy) → self
ext/openssl/ossl_rand.c
View on GitHub ↗
static VALUE
ossl_rand_add(VALUE self, VALUE str, VALUE entropy)
{
StringValue(str);
RAND_add(RSTRING_PTR(str), RSTRING_LENINT(str), NUM2DBL(entropy));
return self;
}
Mixes the bytes from str into the Pseudo Random Number Generator(PRNG) state.
Thus, if the data from str are unpredictable to an adversary, this increases the uncertainty about the state and makes the PRNG output less predictable.
The entropy argument is (the lower bound of) an estimate of how much randomness is contained in str, measured in bytes.
Example
Example
pid = $$ now = Time.now ary = [now.to_i, now.nsec, 1000, pid] OpenSSL::Random.add(ary.join, 0.0) OpenSSL::Random.seed(ary.join)