Class: RealRand::RandomOrg
Instance Attribute Summary
#host, #proxy_host, #proxy_port, #proxy_pwd, #proxy_usr, #ssl
Instance Method Summary
collapse
Constructor Details
Returns a new instance of RandomOrg.
55
56
57
|
# File 'lib/random/online.rb', line 55
def initialize
super("www.random.org",true)
end
|
Instance Method Details
#quota(ip = nil) ⇒ Object
120
121
122
123
124
125
|
# File 'lib/random/online.rb', line 120
def quota(ip=nil)
parameters = "format=plain"
parameters += "&ip=#{ip}" if ip
response = get_response("/quota/", parameters)
convert_result(response.body).first
end
|
#randbyte(nbytes = 256) ⇒ Object
Note: randbyte is deprecated, should use ‘/integers/’ instead. Network load decrease if using hex format instead here?
75
76
77
78
79
80
81
82
83
|
# File 'lib/random/online.rb', line 75
def randbyte(nbytes = 256)
if nbytes <= 0 || nbytes > 16_384
raise RangeError, "Invalid amount: #{nbytes}."
end
return [] if nbytes == 0
parameters = "nbytes=#{nbytes}&format=d"
response = get_response("/cgi-bin/randbyte", parameters)
convert_result(response.body)
end
|
#randnum(num = 100, min = 1, max = 100, args = {}) ⇒ Object
Also known as:
integers
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/random/online.rb', line 59
def randnum(num = 100, min = 1, max = 100, args = {})
check_amount_requested(num)
check_min_max_range(min, max)
parameters = "num=#{num}&min=#{min}&max=#{max}&col=#{num}"
parameters << "&format=plain&base=10"
parameters << "&rnd=#{args[:rnd]}" if args[:rnd]
response = get_response("/integers/", parameters)
convert_result(response.body)
end
|
#randseq(min = 1, max = 100, args = {}) ⇒ Object
Also known as:
sequences
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/random/online.rb', line 85
def randseq(min = 1, max = 100, args = {})
check_min_max_range(min, max)
parameters = "min=#{min}&max=#{max}&col=1"
parameters << "&format=plain" parameters << "&rnd=#{args[:rnd]}" if args[:rnd]
response = get_response("/sequences/", parameters)
convert_result(response.body)
end
|
#randstring(num, len, args = {}) ⇒ Object
Also known as:
strings
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/random/online.rb', line 98
def randstring(num, len, args = {})
default_args = {
:digits => :on,
:upperalpha =>:on,
:loweralpha =>:on,
:unique => :off,
}
args = default_args.update(args)
check_amount_requested(num)
check_num_within(len, 1, 20, 'length')
parameters = "num=#{num}&len=#{len}&format=plain"
parameters << "&" << hash_args_to_params(args)
response = get_response("/strings/", parameters)
response.body.split
end
|