Module: Guid_Unix_

Included in:
Guid
Defined in:
lib/guid.rb

Constant Summary collapse

@@random_device =
nil

Instance Method Summary collapse

Instance Method Details

#initializeObject


68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/guid.rb', line 68

def initialize
  if !@@random_device
    if File.exists? "/dev/urandom"
      @@random_device = File.open "/dev/urandom", "r"
    elsif File.exists? "/dev/random"
      @@random_device = File.open "/dev/random", "r"
    else
      raise RuntimeError, "Can't find random device"
    end
  end

  @bytes = @@random_device.read(16)
end