super_random 0.2.0 → 1.0.0
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.
- checksums.yaml +4 -4
- data/README.rdoc +2 -2
- data/lib/super_random.rb +6 -4
- data/lib/super_random/super_random.rb +53 -15
- metadata +6 -27
- data/lib/super_random/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6d36ed17afa6309e19fc5f03562748be1916766
|
4
|
+
data.tar.gz: 897db2d0dace060590a2b7377589e1d8f9fc6dfc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 012f6e01c1376b9731e0be3c92b623fd8ad23a5cbb17278c7892292a17979f1703135999f57e48957ca6c0df4dac338839b7f344016db8ec70af748182e0dc6d
|
7
|
+
data.tar.gz: 97f7b95fcf20cfb4288e22a1af2863bb0972b45b8736c293d84add8d4c9d41f84df142fd681e7d86c3298fab595832b8eb00dc35bee3e9edc8f10a2bd2efef76
|
data/README.rdoc
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
You can't get more random than random, but you can try really, really, really hard.
|
8
8
|
|
9
|
-
SuperRandom combines
|
9
|
+
SuperRandom combines four online real random services to create a more perfect random byte.
|
10
10
|
|
11
11
|
== SYNOPSIS:
|
12
12
|
|
@@ -36,7 +36,7 @@ SuperRandom combines RealRand's three online real random services to create a mo
|
|
36
36
|
|
37
37
|
(The MIT License)
|
38
38
|
|
39
|
-
Copyright (c)
|
39
|
+
Copyright (c) 2017 carlosjhr64
|
40
40
|
|
41
41
|
Permission is hereby granted, free of charge, to any person obtaining
|
42
42
|
a copy of this software and associated documentation files (the
|
data/lib/super_random.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
+
class SuperRandom
|
2
|
+
VERSION = '1.0.0'
|
3
|
+
end
|
4
|
+
|
1
5
|
# Standard Libraries
|
2
6
|
require 'timeout'
|
3
7
|
require 'securerandom'
|
4
|
-
|
5
|
-
|
6
|
-
require 'random/online'
|
8
|
+
require 'net/http'
|
9
|
+
require 'json'
|
7
10
|
|
8
11
|
# This Gem
|
9
|
-
require 'super_random/version.rb'
|
10
12
|
require 'super_random/super_random.rb'
|
11
13
|
|
12
14
|
# Requires:
|
@@ -1,9 +1,49 @@
|
|
1
1
|
class SuperRandom
|
2
2
|
|
3
|
-
def self.
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
def self.quantum(n)
|
4
|
+
s = Net::HTTP.get(URI(
|
5
|
+
"https://qrng.anu.edu.au/API/jsonI.php?length=#{n}&type=uint8"))
|
6
|
+
a = JSON.parse(s)['data']
|
7
|
+
raise unless a.is_a?(Array) and a.length==n
|
8
|
+
raise unless a.all?{|i| i.is_a?(Integer) and i>-1 and i<256}
|
9
|
+
return a
|
10
|
+
rescue StandardError
|
11
|
+
warn "quantum (qrng.anu.edu.au) failed."
|
12
|
+
return nil
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.atmospheric(n)
|
16
|
+
s = Net::HTTP.get(URI(
|
17
|
+
"https://www.random.org/integers/?num=#{n}&min=0&max=255&col=1&base=10&format=plain&rnd=new"))
|
18
|
+
a = s.strip.split(/\s+/).map{|j|j.to_i}
|
19
|
+
raise unless a.length==n
|
20
|
+
raise unless a.all?{|i| i>-1 and i<256}
|
21
|
+
return a
|
22
|
+
rescue StandardError
|
23
|
+
warn "atmospheric (www.random.org) failed."
|
24
|
+
return nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.entropy_pool(n)
|
28
|
+
s = Net::HTTP.get(URI(
|
29
|
+
"http://random.hd.org/getBits.jsp?numBytes=#{n}&type=bin"))
|
30
|
+
a = s.bytes
|
31
|
+
# As of the time of this writting, not guaranteed to get more than 8 bytes.
|
32
|
+
raise unless (n>8)? a.length.between?(8,n) : a.length==n
|
33
|
+
return a
|
34
|
+
rescue StandardError
|
35
|
+
warn "entropy_pool (random.hd.org) failed."
|
36
|
+
return nil
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.hotbits(n, k='Pseudorandom')
|
40
|
+
s = Net::HTTP.get(URI(
|
41
|
+
"https://www.fourmilab.ch/cgi-bin/Hotbits.api?nbytes=#{n}&fmt=bin&apikey=#{k}"))
|
42
|
+
a = s.bytes
|
43
|
+
raise unless a.length==n
|
44
|
+
return a
|
45
|
+
rescue StandardError
|
46
|
+
warn "hotbits (www.fourmilab.ch) failed."
|
7
47
|
return nil
|
8
48
|
end
|
9
49
|
|
@@ -22,27 +62,25 @@ class SuperRandom
|
|
22
62
|
@randomness = 0.0
|
23
63
|
@services = 0
|
24
64
|
|
25
|
-
|
26
|
-
r2 = RealRand::EntropyPool.new
|
27
|
-
r3 = RealRand::FourmiLab.new
|
28
|
-
|
29
|
-
a1 = a2 = a3 = nil
|
65
|
+
a1 = a2 = a3 = a4 = nil
|
30
66
|
|
31
|
-
t1 = Thread.new{ a1 = SuperRandom.
|
32
|
-
t2 = Thread.new{ a2 = SuperRandom.
|
33
|
-
t3 = Thread.new{ a3 = SuperRandom.
|
67
|
+
t1 = Thread.new{ a1 = SuperRandom.quantum(n)}
|
68
|
+
t2 = Thread.new{ a2 = SuperRandom.atmospheric(n)}
|
69
|
+
t3 = Thread.new{ a3 = SuperRandom.entropy_pool(n)}
|
70
|
+
t4 = Thread.new{ a4 = SuperRandom.hotbits(n)}
|
34
71
|
|
35
72
|
begin
|
36
73
|
Timeout.timeout(@first_timeout) do
|
37
74
|
# Initially, would like to get them all.
|
38
|
-
t1.join and t2.join and t3.join
|
75
|
+
t1.join and t2.join and t3.join and t4.join
|
39
76
|
end
|
40
77
|
rescue Timeout::Error
|
41
78
|
begin
|
42
79
|
Timeout.timeout(@second_timeout) do
|
43
80
|
# But at this point,
|
44
81
|
# would like to get at least one.
|
45
|
-
while a1.nil? and a2.nil? and a3.nil? and
|
82
|
+
while a1.nil? and a2.nil? and a3.nil? and a4.nil?
|
83
|
+
(t1.alive? or t2.alive? or t3.alive? or t4.alive?)
|
46
84
|
Thread.pass
|
47
85
|
end
|
48
86
|
end
|
@@ -53,7 +91,7 @@ class SuperRandom
|
|
53
91
|
end
|
54
92
|
|
55
93
|
a = n.times.inject([]){|b,i|b.push(SecureRandom.random_number(256))}
|
56
|
-
[a1, a2, a3].each do |b|
|
94
|
+
[a1, a2, a3, a4].each do |b|
|
57
95
|
if b
|
58
96
|
bl = b.length
|
59
97
|
@randomness += bl.to_f/n.to_f
|
metadata
CHANGED
@@ -1,39 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: super_random
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- carlosjhr64
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: realrand
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '2.0'
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 2.0.2
|
23
|
-
type: :runtime
|
24
|
-
prerelease: false
|
25
|
-
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
requirements:
|
27
|
-
- - "~>"
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '2.0'
|
30
|
-
- - ">="
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 2.0.2
|
11
|
+
date: 2017-08-22 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
33
13
|
description: |
|
34
14
|
You can't get more random than random, but you can try really, really, really hard.
|
35
15
|
|
36
|
-
SuperRandom combines
|
16
|
+
SuperRandom combines four online real random services to create a more perfect random byte.
|
37
17
|
email: carlosjhr64@gmail.com
|
38
18
|
executables: []
|
39
19
|
extensions: []
|
@@ -43,7 +23,6 @@ files:
|
|
43
23
|
- README.rdoc
|
44
24
|
- lib/super_random.rb
|
45
25
|
- lib/super_random/super_random.rb
|
46
|
-
- lib/super_random/version.rb
|
47
26
|
homepage: https://github.com/carlosjhr64/super_random
|
48
27
|
licenses:
|
49
28
|
- MIT
|
@@ -65,9 +44,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
44
|
- !ruby/object:Gem::Version
|
66
45
|
version: '0'
|
67
46
|
requirements:
|
68
|
-
- 'ruby: ruby 2.
|
47
|
+
- 'ruby: ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]'
|
69
48
|
rubyforge_project:
|
70
|
-
rubygems_version: 2.
|
49
|
+
rubygems_version: 2.6.11
|
71
50
|
signing_key:
|
72
51
|
specification_version: 4
|
73
52
|
summary: You can't get more random than random, but you can try really, really, really
|
data/lib/super_random/version.rb
DELETED