mikedamage-random-org 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile ADDED
@@ -0,0 +1,38 @@
1
+ h1. Random.org Gem
2
+
3
+ _Random integers, baked fresh daily._
4
+
5
+ by Mike Green
6
+
7
+
8
+ h2. Summary
9
+
10
+ This is my first attempt at creating a Ruby gem. It's a really simple class that uses "Random.org's":http://random.org key-value interface to generate a user-specified number of random integers. It's mostly just so I can teach myself basic gem development, but I can see it being useful in web applications that need a reliable, _true_ random number generator.
11
+
12
+ The Random.org Gem is a module that currently contains only one class: @RandomOrg::Integer@, which is an interface to Random.org's "random integer generator":http://random.org/integers/ service. Eventually it will also contain a class that generates sequences of random integers, corresponding to Random.org's "sequence generator":http://random.org/sequences/. Obviously, the Random.org Gem requires an active internet connection to work.
13
+
14
+ h2. Usage
15
+
16
+ Usage is pretty straightforward -- the only method is @new(min, max, base)@, where @base@ is either 2, 8, 10, or 16. The default setting is to generate a random base 10 (decimal) integer. Right now, if you choose to generate a hexidecimal integer, it will give you a string. Mostly because I'm lazy.
17
+
18
+ <pre>
19
+ require 'random_org'
20
+
21
+ int = RandomOrg::Integer.new(0, 100) # base defaults to 10
22
+ puts int.value # That's your randomly generated integer.
23
+ </pre>
24
+
25
+ h2. Dependencies
26
+
27
+ * Ruby Standard Library _(that's it)_
28
+
29
+ h2. About "Random.org":http://random.org
30
+
31
+ _From their website:_
32
+
33
+ *RANDOM.ORG* offers true random numbers to anyone on the Internet. The randomness comes from atmospheric noise, which for many purposes is better than the pseudo-random number algorithms typically used in computer programs. People use RANDOM.ORG for holding draws, lotteries and sweepstakes, to drive games and gambling sites, for scientific applications and for art and music. The service has existed since 1998 and was built and is being operated by Mads Haahr of the School of Computer Science and Statistics at Trinity College, Dublin in Ireland.
34
+
35
+
36
+ h2. COPYRIGHT
37
+
38
+ Copyright (c) 2008 Mike Green. See LICENSE for details.
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :minor: 1
3
+ :patch: 0
4
+ :major: 0
data/lib/random_org.rb ADDED
@@ -0,0 +1,31 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+
4
+ module RandomOrg
5
+
6
+ class Integer
7
+ @@url = URI.parse("http://random.org/integers/")
8
+ ValidBases = [2, 8, 10, 16]
9
+
10
+ attr_reader :min, :max, :base, :value, :opts
11
+
12
+ def initialize(min, max, base=10)
13
+ @min = min.to_s
14
+ @max = max.to_s
15
+ @base = base.to_s
16
+ @@url.query = "num=1&min=#{@min}&max=#{@max}&col=1&base=#{@base}&format=plain&rnd=new"
17
+
18
+ begin
19
+ res = Net::HTTP.get(@@url).chomp
20
+ if @base.to_i == 16
21
+ @value = res
22
+ else
23
+ @value = res.to_i
24
+ end
25
+ rescue Net::HTTPFatalError => e
26
+ puts "Error: " + e
27
+ end
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class RandomOrgTest < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'mocha'
5
+
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'random_org'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mikedamage-random-org
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mike Green
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-01-28 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: TODO
17
+ email: mike.is.green@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - README.textile
26
+ - VERSION.yml
27
+ - lib/random_org.rb
28
+ - test/random_org_test.rb
29
+ - test/test_helper.rb
30
+ has_rdoc: true
31
+ homepage: http://github.com/mikedamage/random-org
32
+ post_install_message:
33
+ rdoc_options:
34
+ - --inline-source
35
+ - --charset=UTF-8
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: "0"
43
+ version:
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ requirements: []
51
+
52
+ rubyforge_project:
53
+ rubygems_version: 1.2.0
54
+ signing_key:
55
+ specification_version: 2
56
+ summary: TODO
57
+ test_files: []
58
+