true-random 1.1.0 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,112 @@
1
+ # TrueRandom
2
+ Get true random numbers from [RANDOM.ORG](http://random.org).
3
+
4
+ # Description
5
+ Use the true random number service of [RANDOM.ORG](http://random.org). The randomness comes from atmospheric noise, which for many purposes is better than the pseudo-random number algorithms typically used in computer programs.
6
+
7
+
8
+ #Installation
9
+ ##From the command line.
10
+
11
+ ```shell
12
+ gem install true-random
13
+ ```
14
+
15
+ ##Using Gemfile.
16
+
17
+ 1 Add to your application Gemfile
18
+
19
+ ```ruby
20
+ gem 'true-random'
21
+ ```
22
+
23
+ 2 Type
24
+
25
+ ```shell
26
+ bundle install
27
+ ```
28
+
29
+ ##Important note!
30
+ To access [RANDOM.ORG](http://random.org) via an automated client, please make sure you observe the [Guidelines for Automated Clients](http://www.random.org/clients/) or your computer may be banned.
31
+
32
+ #Usage
33
+ ##Integer Generator
34
+ The Integer Generator will generate truly random integers in configurable intervals.
35
+
36
+ ```ruby
37
+ rnd = TrueRandom::Random.new
38
+ puts rnd.integer
39
+ ```
40
+
41
+ **Parameters**
42
+ *n* The number of integers requested. 1 by default.
43
+ *min* The smallest value allowed for each integer. 1 by default.
44
+ *max* The largest value allowed for each integer. 100 by default.
45
+ *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.
46
+
47
+ The same example with full parameters
48
+
49
+ ```ruby
50
+ rnd = TrueRandom::Random.new
51
+ puts rnd.integer 1, 2, 100, 10
52
+ ```
53
+
54
+ ##Sequence Generator
55
+ The Sequence Generator will randomize a given interval of integers, i.e., arrange them in random order.
56
+
57
+ ```ruby
58
+ rnd = TrueRandom::Random.new
59
+ puts rnd.sequence
60
+ ```
61
+
62
+ **Parameters**
63
+ *min* The lower bound of the interval (inclusive). 1 by default.
64
+ *max* The upper bound of the interval (inclusive). 100 by default.
65
+
66
+ The sequence requested must 10,000 numbers or shorter in length, i.e., max-min+1=1e4.
67
+
68
+ ##String Generator
69
+ The String Generator will generate truly random strings of various length and character compositions.
70
+
71
+ ```ruby
72
+ rnd = TrueRandom::Random.new
73
+ puts rnd.string
74
+ ```
75
+
76
+ **Parameters**
77
+ *n* The number of strings requested. 1 by default.
78
+ *len* The length of the strings. All the strings produced will have the same length. Max length 20. 20 by default.
79
+ *digits* Determines whether digits (0-9) are allowed to occur in the strings. Possible values are true or false. True by default.
80
+ *upperalpha* Determines whether uppercase alphabetic characters (A-Z) are allowed to occur in the strings. Possible values are true or false. True by default.
81
+ *loweralpha* Determines lowercase alphabetic characters (a-z) are allowed to occur in the strings. Possible values are true or false. True by default.
82
+ *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.
83
+
84
+ ##Quota Checker
85
+ The Quota Checker allows you to examine your quota at any point in time. The quota system works on the basis of IP addresses. Each IP address has a base quota of 1,000,000 bits. When your client makes a request for random numbers (or strings, etc.), the server deducts the number of bits it took to satisfy your request from the quota associated with your client's IP address.
86
+
87
+ ```ruby
88
+ rnd = TrueRandom::Random.new
89
+ puts rnd.quota
90
+ ```
91
+
92
+ You can request for certain IP.
93
+
94
+ ```ruby
95
+ rnd = TrueRandom::Random.new
96
+ puts rnd.quota 'n.n.n.n'
97
+ ```
98
+
99
+ n.n.n.n is the IP address for which you wish to examine the quota. Each value for n should be an integer in the [0,255] interval. This parameter is optional. If you leave it out, it defaults to the IP address of the machine from which you are issuing the request.
100
+
101
+ ##Using proxy server
102
+ To enable proxy feature, set a proxy host.
103
+
104
+ ```ruby
105
+ rnd = TrueRandom::Random.new
106
+ rnd.proxy host, port
107
+ puts rnd.integer
108
+ ```
109
+
110
+ Set host to false to disable proxy.
111
+
112
+ Default port is 8080.
@@ -2,6 +2,10 @@ require 'net/http'
2
2
 
3
3
  module TrueRandom
4
4
  class Random
5
+ def initialize
6
+ @proxy_url = false
7
+ end
8
+
5
9
  def integer n=1, min=1, max=100, base = 10
6
10
  return integers "integers/?num=#{n}&min=#{min}&max=#{max}&col=1&base=#{base}"
7
11
  end
@@ -20,9 +24,13 @@ module TrueRandom
20
24
  else
21
25
  return integers "quota/?ip=#{ip}"
22
26
  end
23
-
24
27
  end
25
28
 
29
+ def proxy url = false, port = 8080
30
+ @proxy_url = url
31
+ @proxy_port = port
32
+ end
33
+
26
34
  private
27
35
  def on_off value = false
28
36
  return value == true ? 'on' : 'off'
@@ -45,7 +53,12 @@ module TrueRandom
45
53
  end
46
54
 
47
55
  def request uri
48
- http_response = Net::HTTP.get_response(URI.parse('http://www.random.org/' + uri + '&format=plain&rnd=new'))
56
+ url = URI.parse('http://www.random.org/' + uri + '&format=plain&rnd=new')
57
+ http_response = Net::HTTP::Proxy(@proxy_url, @proxy_port).get_response(url)
58
+ if @proxy_url
59
+ else
60
+ http_response = Net::HTTP.get_response(url)
61
+ end
49
62
  return false unless http_response.code.to_i == 200
50
63
  results = []
51
64
  http_response.body.split("\n").each do |item|
@@ -1,3 +1,3 @@
1
1
  module TrueRandom
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.2"
3
3
  end
metadata CHANGED
@@ -1,19 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: true-random
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Miguel Adolfo Barroso
9
+ - eonrubia
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2012-02-07 00:00:00.000000000Z
13
+ date: 2012-02-12 00:00:00.000000000Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: rspec
16
- requirement: &13598540 !ruby/object:Gem::Requirement
17
+ requirement: &10415460 !ruby/object:Gem::Requirement
17
18
  none: false
18
19
  requirements:
19
20
  - - ~>
@@ -21,7 +22,7 @@ dependencies:
21
22
  version: 2.7.0
22
23
  type: :development
23
24
  prerelease: false
24
- version_requirements: *13598540
25
+ version_requirements: *10415460
25
26
  description: Use the true random number service of RANDOM.ORG. The randomness comes
26
27
  from atmospheric noise, which for many purposes is better than the pseudo-random
27
28
  number algorithms typically used in computer programs.
@@ -35,7 +36,7 @@ files:
35
36
  - lib/true-random.rb
36
37
  - MIT-LICENSE
37
38
  - Rakefile
38
- - README.rdoc
39
+ - README.md
39
40
  homepage: http://github.com/mabarroso/true-random
40
41
  licenses: []
41
42
  post_install_message:
@@ -1,85 +0,0 @@
1
- = true-random
2
- Get true random numbers from RANDOM.ORG.
3
-
4
- = Description
5
- Use the true random number service of RANDOM.ORG. The randomness comes from
6
- atmospheric noise, which for many purposes is better than the pseudo-random
7
- number algorithms typically used in computer programs.
8
-
9
-
10
- =Installation
11
- ==From the command line.
12
- gem install true-random
13
-
14
- ==Using Gemfile.
15
-
16
- 1 Add to your application Gemfile
17
- gem 'true-random'
18
-
19
- 2 Type
20
- bundle install
21
-
22
- =Important note!
23
- To access RANDOM.ORG via an automated client, please make sure you observe the Guidelines for Automated Clients
24
- (http://www.random.org/clients/) or your computer may be banned.
25
-
26
- =Usage
27
- ==Integer Generator
28
- The Integer Generator will generate truly random integers in configurable intervals.
29
- rnd = TrueRandom::Random.new
30
- puts rnd.integer
31
-
32
- Parameters
33
- n The number of integers requested. 1 by default.
34
- min The smallest value allowed for each integer. 1 by default.
35
- max The largest value allowed for each integer. 100 by default.
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.
37
-
38
- The same example with full parameters
39
- rnd = TrueRandom::Random.new
40
- puts rnd.integer 1, 2, 100, 10
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
-