super_random 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c2bdb90bf409bb64add4cf601921e1edc2cc36df
4
+ data.tar.gz: 70182e1e2085a142c23d9a10cfce4a7d2aae88a0
5
+ SHA512:
6
+ metadata.gz: 938dc8720619cb664c496dec62b585bf83fca722545e90d9583a44923ad0ec3c1562fe6c5659581e8424a96df10a857de579c105b3d998df0ff35f8959def1d4
7
+ data.tar.gz: deee15aaeabca26b2c7d635625bd0f94b946d27615f741e211e13ffa48c627f4d6c14a6700338f8e028c9a4baddfb518a10a5be79df1d811c2f795015dbfc978
data/README.rdoc ADDED
@@ -0,0 +1,58 @@
1
+ = super_random
2
+
3
+ {<img src="https://badge.fury.io/rb/super_random.svg" alt="Gem Version" />}[http://badge.fury.io/rb/super_random]
4
+
5
+ == DESCRIPTION:
6
+
7
+ You can't get more random than random, but you can try really, really, really hard.
8
+
9
+ SuperRandom combines RealRand's three online real random services to create a more perfect random byte.
10
+
11
+ == SYNOPSIS:
12
+
13
+ require 'super_random' #=> true
14
+ super_random = SuperRandom.new # => #<SuperRandom:...
15
+
16
+ # bytes returns 32 bytes by default (256 bits).
17
+ super_random.bytes # => [123, 219, 128, ..., 248, 164, 100]
18
+
19
+ # hexadecimal returns a 32 bytes hexadecimal by default.
20
+ super_random.hexadecimal #=> "2ae...37b"
21
+
22
+ # rand as the typical use
23
+ super_random.rand #=> 0.16882225652425537
24
+ super_random.rand(100) #=> 85
25
+
26
+ # The "randomness" attribute gives the number of online services used.
27
+ # It's possible for a service to fail.
28
+ # Ultimately, SuperRandom uses SecureRandom as a failsafe.
29
+ super_random.randomness #=> 3
30
+
31
+ == INSTALL:
32
+
33
+ $ sudo gem install super_random
34
+
35
+ == LICENSE:
36
+
37
+ (The MIT License)
38
+
39
+ Copyright (c) 2014 carlosjhr64
40
+
41
+ Permission is hereby granted, free of charge, to any person obtaining
42
+ a copy of this software and associated documentation files (the
43
+ 'Software'), to deal in the Software without restriction, including
44
+ without limitation the rights to use, copy, modify, merge, publish,
45
+ distribute, sublicense, and/or sell copies of the Software, and to
46
+ permit persons to whom the Software is furnished to do so, subject to
47
+ the following conditions:
48
+
49
+ The above copyright notice and this permission notice shall be
50
+ included in all copies or substantial portions of the Software.
51
+
52
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
53
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
54
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
55
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
56
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
57
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
58
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,13 @@
1
+ # Standard Libraries
2
+ require 'timeout'
3
+ require 'securerandom'
4
+
5
+ # Helper Gem
6
+ require 'random/online'
7
+
8
+ # This Gem
9
+ require 'super_random/version.rb'
10
+ require 'super_random/super_random.rb'
11
+
12
+ # Requires:
13
+ #`ruby`
@@ -0,0 +1,65 @@
1
+ class SuperRandom
2
+
3
+ attr_accessor :first_timeout, :second_timeout, :length, :nevermind, :randomness
4
+ def initialize
5
+ @first_timeout = 3
6
+ @second_timeout = 6
7
+ @nevermind = true
8
+ @randomness = 0
9
+ end
10
+
11
+ def bytes(n=32)
12
+ @randomness = 0
13
+
14
+ r1 = RealRand::RandomOrg.new
15
+ r2 = RealRand::EntropyPool.new
16
+ r3 = RealRand::FourmiLab.new
17
+
18
+ a1 = a2 = a3 = nil
19
+
20
+ t1 = Thread.new{ a1 = r1.randbyte(n) }
21
+ t2 = Thread.new{ a2 = r2.randbyte(n) }
22
+ t3 = Thread.new{ a3 = r3.randbyte(n) }
23
+
24
+ begin
25
+ Timeout.timeout(@first_timeout) do
26
+ # Initially, would like to get them all.
27
+ t1.join and t2.join and t3.join
28
+ end
29
+ rescue Timeout::Error
30
+ begin
31
+ Timeout.timeout(@second_timeout) do
32
+ # But at this point,
33
+ # would like to get at least one.
34
+ while a1.nil? and a2.nil? and a3.nil? and (t1.alive? or t2.alive? or t3.alive?)
35
+ Thread.pass
36
+ end
37
+ end
38
+ rescue Timeout::Error
39
+ # If we don't care that we got nothing, go on.
40
+ raise $! unless @nevermind
41
+ end
42
+ end
43
+
44
+ a = n.times.inject([]){|a,i|a.push(SecureRandom.random_number(256))}
45
+
46
+ [a1, a2, a3].each do |b|
47
+ if b
48
+ @randomness += 1
49
+ n.times{|i|a[i]=(a[i]+b[i])%256}
50
+ end
51
+ end
52
+
53
+ return a
54
+ end
55
+
56
+ def hexadecimal(n=32)
57
+ bytes(n).map{|i|i.to_s(16).rjust(2,'0')}.join
58
+ end
59
+
60
+ def rand(m=nil, n=6)
61
+ div = n.times.inject(''){|s,i| s+'FF'}.to_i(16).to_f
62
+ r = hexadecimal(n).to_i(16).to_f / div
63
+ m.nil? ? r : (m*r).to_i
64
+ end
65
+ end
@@ -0,0 +1,3 @@
1
+ class SuperRandom
2
+ VERSION = '0.0.0'
3
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: super_random
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - carlosjhr64
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |
14
+ You can't get more random than random, but you can try really, really, really hard.
15
+
16
+ SuperRandom combines RealRand's three online real random services to create a more perfect random byte.
17
+ email: carlosjhr64@gmail.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files:
21
+ - README.rdoc
22
+ files:
23
+ - README.rdoc
24
+ - lib/super_random.rb
25
+ - lib/super_random/super_random.rb
26
+ - lib/super_random/version.rb
27
+ homepage: https://github.com/carlosjhr64/super_random
28
+ licenses:
29
+ - MIT
30
+ metadata: {}
31
+ post_install_message:
32
+ rdoc_options:
33
+ - "--main"
34
+ - README.rdoc
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements:
48
+ - 'ruby: ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-linux]'
49
+ rubyforge_project:
50
+ rubygems_version: 2.4.1
51
+ signing_key:
52
+ specification_version: 4
53
+ summary: You can't get more random than random, but you can try really, really, really
54
+ hard.
55
+ test_files: []
56
+ has_rdoc: