I am creating a pastebin app and I want the pastes’ IDs to be truly random. /dev/random on Linux (hosted on a Linux machine) uses noise so it’s output is truly random.
Currently I use this code to generate the IDs:
self.guid = Digest::SHA1.hexdigest(Time.new.to_s + (0...50).map{ ('a'..'z').to_a[rand(26)] }.join)
Does Ruby’s rand function use /dev/random, and if not how can I use /dev/random in Ruby? Thanks.
The hardly documented SecureRandom (standard lib in ruby 1.9.2) uses OpenSSL (which is faster than urandom), if not available it uses urandom, last it checks if win32’s random is
available. If none you’ll get an error.
It has nice features:
(uuid: RFC 4122)