Class: RealRand::RandomOrg
Instance Attribute Summary
#host, #proxy_host, #proxy_port, #proxy_pwd, #proxy_usr
Instance Method Summary
collapse
Constructor Details
Returns a new instance of RandomOrg.
53
54
55
|
# File 'lib/random/online.rb', line 53
def initialize
super("www.random.org")
end
|
Instance Method Details
#quota(ip = nil) ⇒ Object
118
119
120
121
122
123
|
# File 'lib/random/online.rb', line 118
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?
73
74
75
76
77
78
79
80
81
|
# File 'lib/random/online.rb', line 73
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
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/random/online.rb', line 57
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
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/random/online.rb', line 83
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/random/online.rb', line 96
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
|