Class: RealRand::FourmiLab

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

#initializeFourmiLab

Returns a new instance of FourmiLab.



188
189
190
# File 'lib/random/online.rb', line 188

def initialize
  super("www.fourmilab.ch")
end

Instance Method Details

#randbyte(nbytes = 128) ⇒ Object



192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/random/online.rb', line 192

def randbyte(nbytes = 128)
  if nbytes < 0 || nbytes > 2048
    raise RangeError, "Invalid amount: #{nbytes}."
  end
  return [] if nbytes == 0
  parameters = "nbytes=#{nbytes}&fmt=bin"
  response = get_response("/cgi-bin/uncgi/Hotbits", 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