Does Ruby on Linux use / dev / random?

I am creating a pastebin application and want the paste IDs to be really random. /dev/randomon Linux (hosted on a Linux machine) uses noise, so the output is really random.

I am currently using this code to generate identifiers:

self.guid = Digest::SHA1.hexdigest(Time.new.to_s + (0...50).map{ ('a'..'z').to_a[rand(26)] }.join)

Does Ruby use a randfunction /dev/random, and if not, how can I use /dev/randomin Ruby? Thank.

+3
source share
2 answers

documented SecureRandom ( lib ruby โ€‹โ€‹1.9.2) OpenSSL ( , ), , urandom, , win32 random . , . :

require 'securerandom'
puts SecureRandom.urlsafe_base64(50)
#=> thgv48AT_gGcYD3xx-lCqRWjoAFqN3pm2ZBKOZPZP2BC0aSMD5rXg1EaPzKLbJMMt4Y
puts SecureRandom.uuid
#=> 2670f82a-0aee-41a8-93c5-2d08e2c608db 

(uuid: RFC 4122)

+12

, Mersenne, , .

, Ruby, , . grep ruby-1.9.2-p0 /dev/urandom (, OpenSolaris), , , USE_DEV_URANDOM.

/dev/random , . .

+3

Source: https://habr.com/ru/post/1794813/


All Articles