Skip to content

End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

OpenSSL::Random.random_add

add(str, entropy) → 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)
See also .load_random_file .random_bytes .egd_bytes .seed also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0