true-random 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +46 -1
- data/lib/true-random.rb +35 -2
- data/lib/true-random/version.rb +1 -1
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -25,6 +25,7 @@ To access RANDOM.ORG via an automated client, please make sure you observe the G
|
|
25
25
|
|
26
26
|
=Usage
|
27
27
|
==Integer Generator
|
28
|
+
The Integer Generator will generate truly random integers in configurable intervals.
|
28
29
|
rnd = TrueRandom::Random.new
|
29
30
|
puts rnd.integer
|
30
31
|
|
@@ -32,9 +33,53 @@ Parameters
|
|
32
33
|
n The number of integers requested. 1 by default.
|
33
34
|
min The smallest value allowed for each integer. 1 by default.
|
34
35
|
max The largest value allowed for each integer. 100 by default.
|
35
|
-
base The base that will be used to print the numbers, i.e., binary, octal, decimal or hexadecimal. Possible values are
|
36
|
+
base The base that will be used to print the numbers, i.e., binary, octal, decimal or hexadecimal. Possible values are 2, 8, 10 or 16. 10 by default.
|
36
37
|
|
37
38
|
The same example with full parameters
|
38
39
|
rnd = TrueRandom::Random.new
|
39
40
|
puts rnd.integer 1, 2, 100, 10
|
40
41
|
|
42
|
+
==Sequence Generator
|
43
|
+
The Sequence Generator will randomize a given interval of integers, i.e., arrange them in random order.
|
44
|
+
rnd = TrueRandom::Random.new
|
45
|
+
puts rnd.sequence
|
46
|
+
|
47
|
+
Parameters
|
48
|
+
min The lower bound of the interval (inclusive). 1 by default.
|
49
|
+
max The upper bound of the interval (inclusive). 100 by default.
|
50
|
+
|
51
|
+
The sequence requested must 10,000 numbers or shorter in length, i.e., max-min+1=1e4.
|
52
|
+
|
53
|
+
==String Generator
|
54
|
+
The String Generator will generate truly random strings of various length and character compositions.
|
55
|
+
rnd = TrueRandom::Random.new
|
56
|
+
puts rnd.string
|
57
|
+
|
58
|
+
Parameters
|
59
|
+
n The number of strings requested. 1 by default.
|
60
|
+
len The length of the strings. All the strings produced will have the same length. Max length 20. 20 by default.
|
61
|
+
digits Determines whether digits (0-9) are allowed to occur in the strings. Possible values are true or false. True by default.
|
62
|
+
upperalpha Determines whether uppercase alphabetic characters (A-Z) are allowed to occur in the strings. Possible values are true or false. True by default.
|
63
|
+
loweralpha Determines lowercase alphabetic characters (a-z) are allowed to occur in the strings. Possible values are true or false. True by default.
|
64
|
+
unique Determines whether the strings picked should be unique (as a series of raffle tickets drawn from a hat) or not (as a series of die rolls). If unique is set to on, then there is the additional constraint that the number of strings requested (num) must be less than or equal to the number of strings that exist with the selected length and characters. Possible values are true or false. True by default.
|
65
|
+
|
66
|
+
==Quota Checker
|
67
|
+
The Quota Checker allows you to examine your quota at any point in time. The
|
68
|
+
quota system works on the basis of IP addresses. Each IP address has a base
|
69
|
+
quota of 1,000,000 bits. When your client makes a request for random numbers
|
70
|
+
(or strings, etc.), the server deducts the number of bits it took to satisfy
|
71
|
+
your request from the quota associated with your client's IP address.
|
72
|
+
|
73
|
+
rnd = TrueRandom::Random.new
|
74
|
+
puts rnd.quota
|
75
|
+
|
76
|
+
You can request for certain IP.
|
77
|
+
|
78
|
+
rnd = TrueRandom::Random.new
|
79
|
+
puts rnd.quota 'n.n.n.n'
|
80
|
+
|
81
|
+
n.n.n.n is the IP address for which you wish to examine the quota. Each value
|
82
|
+
for n should be an integer in the [0,255] interval. This parameter is optional.
|
83
|
+
If you leave it out, it defaults to the IP address of the machine from which
|
84
|
+
you are issuing the request.
|
85
|
+
|
data/lib/true-random.rb
CHANGED
@@ -3,14 +3,47 @@ require 'net/http'
|
|
3
3
|
module TrueRandom
|
4
4
|
class Random
|
5
5
|
def integer n=1, min=1, max=100, base = 10
|
6
|
-
|
6
|
+
return integers "integers/?num=#{n}&min=#{min}&max=#{max}&col=1&base=#{base}"
|
7
|
+
end
|
8
|
+
|
9
|
+
def sequence min=1, max=100
|
10
|
+
return integers "sequences/?min=#{min}&max=#{max}&col=1"
|
11
|
+
end
|
12
|
+
|
13
|
+
def string n = 1, len = 20, digits = true, upperalpha = true, loweralpha = true, unique = true
|
14
|
+
return strings "strings/?num=#{n}&len=#{len}&digits=#{on_off digits}&upperalpha=#{on_off upperalpha}&loweralpha=#{on_off loweralpha}&unique=#{on_off unique}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def quota ip = false
|
18
|
+
if ip
|
19
|
+
return integers "quota/?"
|
20
|
+
else
|
21
|
+
return integers "quota/?ip=#{ip}"
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
def on_off value = false
|
28
|
+
return value == true ? 'on' : 'off'
|
29
|
+
end
|
30
|
+
|
31
|
+
def integers uri
|
32
|
+
response = request uri
|
7
33
|
|
8
34
|
return false unless response
|
9
35
|
return response[0].to_i if response.count == 1
|
10
36
|
return response.collect {|x| x.to_i }
|
11
37
|
end
|
12
38
|
|
13
|
-
|
39
|
+
def strings uri
|
40
|
+
response = request uri
|
41
|
+
|
42
|
+
return false unless response
|
43
|
+
return response[0] if response.count == 1
|
44
|
+
return response
|
45
|
+
end
|
46
|
+
|
14
47
|
def request uri
|
15
48
|
http_response = Net::HTTP.get_response(URI.parse('http://www.random.org/' + uri + '&format=plain&rnd=new'))
|
16
49
|
return false unless http_response.code.to_i == 200
|
data/lib/true-random/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: true-random
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-07 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &13598540 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: 2.7.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *13598540
|
25
25
|
description: Use the true random number service of RANDOM.ORG. The randomness comes
|
26
26
|
from atmospheric noise, which for many purposes is better than the pseudo-random
|
27
27
|
number algorithms typically used in computer programs.
|