summaryrefslogtreecommitdiff
path: root/lib/securerandom.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/securerandom.rb')
-rw-r--r--lib/securerandom.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/securerandom.rb b/lib/securerandom.rb
index 3fd63e535f..a957687a82 100644
--- a/lib/securerandom.rb
+++ b/lib/securerandom.rb
@@ -50,6 +50,14 @@ module SecureRandom
def self.random_bytes(n=nil)
n ||= 16
if defined? OpenSSL::Random
+ @pid = $$ if !defined?(@pid)
+ pid = $$
+ if @pid != pid
+ now = Time.now
+ ary = [now.to_i, now.usec, @pid, pid]
+ OpenSSL::Random.seed(ary.to_s)
+ @pid = pid
+ end
return OpenSSL::Random.random_bytes(n)
end
if !defined?(@has_urandom) || @has_urandom