true-random 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +40 -0
- data/Rakefile +9 -0
- data/lib/true_random.rb +25 -0
- data/lib/true_random/version.rb +3 -0
- metadata +63 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,40 @@
|
|
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
|
+
rnd = TrueRandom::Random.new
|
29
|
+
puts rnd.integer
|
30
|
+
|
31
|
+
Parameters
|
32
|
+
n The number of integers requested. 1 by default.
|
33
|
+
min The smallest value allowed for each integer. 1 by default.
|
34
|
+
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 2, 8, 10 or 16. 10 by default.
|
36
|
+
|
37
|
+
The same example with full parameters
|
38
|
+
rnd = TrueRandom::Random.new
|
39
|
+
puts rnd.integer 1, 2, 100, 10
|
40
|
+
|
data/Rakefile
ADDED
data/lib/true_random.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module TrueRandom
|
4
|
+
class Random
|
5
|
+
def integer n=1, min=1, max=100, base = 10
|
6
|
+
response = request "integers/?num=#{n}&min=#{min}&max=#{max}&col=1&base=#{base}"
|
7
|
+
|
8
|
+
return false unless response
|
9
|
+
return response[0].to_i if response.count == 1
|
10
|
+
return response.collect {|x| x.to_i }
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def request uri
|
15
|
+
http_response = Net::HTTP.get_response(URI.parse('http://www.random.org/' + uri + '&format=plain&rnd=new'))
|
16
|
+
return false unless http_response.code.to_i == 200
|
17
|
+
results = []
|
18
|
+
http_response.body.split("\n").each do |item|
|
19
|
+
results << item
|
20
|
+
end
|
21
|
+
results
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: true-random
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Miguel Adolfo Barroso
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-06 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &18060920 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.7.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *18060920
|
25
|
+
description: Use the true random number service of RANDOM.ORG. The randomness comes
|
26
|
+
from atmospheric noise, which for many purposes is better than the pseudo-random
|
27
|
+
number algorithms typically used in computer programs.
|
28
|
+
email:
|
29
|
+
- mabarroso@mabarroso.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- lib/true_random.rb
|
35
|
+
- lib/true_random/version.rb
|
36
|
+
- MIT-LICENSE
|
37
|
+
- Rakefile
|
38
|
+
- README.rdoc
|
39
|
+
homepage: http://github.com/mabarroso/true-random
|
40
|
+
licenses: []
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 1.8.10
|
60
|
+
signing_key:
|
61
|
+
specification_version: 3
|
62
|
+
summary: Get true random numbers from RANDOM.ORG.
|
63
|
+
test_files: []
|