Guid causes "Can't find random device"
I'm trying to use Guid to generate uniq开发者_如何学Goue ids in my Ruby project. This is a sample ruby file that I created to test its functionality:
require 'guid'
g = Guid.new
puts g
When I run this file, I get this error.
E:/Apps/Ruby186/lib/ruby/site_ruby/1.8/guid.rb:67:in `initialize': Can't find random device (Runtime Error)
from guid_test.rb:3:in `new'
from guid_test.rb:3
What could be the reason for this? I'm using Ruby on a Windows 7 (64 bit) machine.
According to http://www.koders.com/ruby/fid47791138EC0592EEEF2FC1F55408231838DF7CA4.aspx?s=game, the guid source code checks the type of the OS via
if RUBY_PLATFORM =~ /win/i
module Guid_Win32_
require 'Win32API'
Apparently, in your case (Windows 7 64bit), this check fails (RUBY_PLATFORM returns something else (e.g. i386-mingw32 for my Ruby 1.9 installation on Windows7 64bit)), and it tries to use the Unix code, which then tries to open /dev/urandom - this fails.
So you could check what RUBY_PLATFORM returns on your OS, modifiy the guid.rb sourcecode and send a patch to the developers so they can fix it.
精彩评论