summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/securerandom.rb9
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/securerandom.rb b/lib/securerandom.rb
index 9cbf4ea789..07ae048634 100644
--- a/lib/securerandom.rb
+++ b/lib/securerandom.rb
@@ -72,8 +72,11 @@ module SecureRandom
ret
end
- ret = Random.urandom(1)
- if ret.nil?
+ begin
+ # Check if Random.urandom is available
+ Random.urandom(1)
+ alias gen_random gen_random_urandom
+ rescue RuntimeError
begin
require 'openssl'
rescue NoMethodError
@@ -81,8 +84,6 @@ module SecureRandom
else
alias gen_random gen_random_openssl
end
- else
- alias gen_random gen_random_urandom
end
public :gen_random