Class: RealRand::EntropyPool

Inherits:
OnlineGenerator show all
Defined in:
lib/random/online.rb

Instance Attribute Summary

Attributes inherited from OnlineGenerator

#host, #proxy_host, #proxy_port, #proxy_pwd, #proxy_usr, #ssl

Instance Method Summary collapse

Constructor Details

#initializeEntropyPool

Returns a new instance of EntropyPool.



209
210
211
# File 'lib/random/online.rb', line 209

def initialize
  super("random.hd.org")
end

Instance Method Details

#randbyte(nbytes = 16, limit = true) ⇒ Object



213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/random/online.rb', line 213

def randbyte(nbytes = 16, limit = true)
  if nbytes < 0 || nbytes > 256
    raise RangeError, "Invalid amount: #{nbytes}."
  end
  return [] if nbytes == 0
  parameters = "numBytes=#{nbytes}&type=bin&limit=#{limit}"
  response = get_response("/getBits.jsp", parameters)
  if response['content-type'] !~ /application\/octet-stream/
    raise "Unexpected content type: <#{response['content-type']}>."
  end
  result = []
  response.body.each_byte { |b| result << b }
  result
end