super_random 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e6d36ed17afa6309e19fc5f03562748be1916766
4
- data.tar.gz: 897db2d0dace060590a2b7377589e1d8f9fc6dfc
2
+ SHA256:
3
+ metadata.gz: 83691b6150693c16ecc7f602259eceba24a343e7583db204f388015bfe133796
4
+ data.tar.gz: efa9698299c61b3df708f3c8392635d76373e4654129ef093737c7da5a1a9e0d
5
5
  SHA512:
6
- metadata.gz: 012f6e01c1376b9731e0be3c92b623fd8ad23a5cbb17278c7892292a17979f1703135999f57e48957ca6c0df4dac338839b7f344016db8ec70af748182e0dc6d
7
- data.tar.gz: 97f7b95fcf20cfb4288e22a1af2863bb0972b45b8736c293d84add8d4c9d41f84df142fd681e7d86c3298fab595832b8eb00dc35bee3e9edc8f10a2bd2efef76
6
+ metadata.gz: 6c9a8746336cdf86a2643790b0406345ee859ccd5de84868ea834d4e4260908016df5e1b917da9ebbd8848885d7ce1e394c5be17382509b79c773445cbf75dfe
7
+ data.tar.gz: 1437d184fbca7782cf65a2f05d7b6cf424e396de112ac2e928db08836171b5d86fc2da5f015e3962155602c59e693fb8eb97dc5bb8b8a639ff4dc39c5cdb86c7
@@ -1,38 +1,39 @@
1
- = super_random
1
+ # SuperRandom
2
2
 
3
- {<img src="https://badge.fury.io/rb/super_random.svg" alt="Gem Version" />}[http://badge.fury.io/rb/super_random]
3
+ * [github](https://www.github.com/carlosjhr64/super_random)
4
+ * [rubygems](https://rubygems.org/gems/super_random)
4
5
 
5
- == DESCRIPTION:
6
+ ## DESCRIPTION:
6
7
 
7
8
  You can't get more random than random, but you can try really, really, really hard.
8
9
 
9
- SuperRandom combines four online real random services to create a more perfect random byte.
10
+ SuperRandom combines five online real random services to create a more perfect random byte.
10
11
 
11
- == SYNOPSIS:
12
+ ## SYNOPSIS:
12
13
 
13
- require 'super_random' #=> true
14
- super_random = SuperRandom.new # => #<SuperRandom:...
14
+ require 'super_random' #=> true
15
+ super_random = SuperRandom.new # => #<SuperRandom:...
15
16
 
16
- # bytes returns 32 bytes by default (256 bits).
17
- super_random.bytes # => [123, 219, 128, ..., 248, 164, 100]
17
+ # bytes returns 32 bytes by default (256 bits).
18
+ super_random.bytes # => [123, 219, 128, ..., 248, 164, 100]
18
19
 
19
- # hexadecimal returns a 32 bytes hexadecimal by default.
20
- super_random.hexadecimal #=> "2ae...37b"
20
+ # hexadecimal returns a 32 bytes hexadecimal by default.
21
+ super_random.hexadecimal #=> "2ae...37b"
21
22
 
22
- # rand as the typical use
23
- super_random.rand #=> 0.16882225652425537
24
- super_random.rand(100) #=> 85
23
+ # rand as the typical use
24
+ super_random.rand #=> 0.16882225652425537
25
+ super_random.rand(100) #=> 85
25
26
 
26
- # The "services" 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.services #=> 3
27
+ # The "services" attribute gives the number of online services used.
28
+ # It's possible for a service to fail.
29
+ # Ultimately, SuperRandom uses SecureRandom as a failsafe.
30
+ super_random.services #=> 5
30
31
 
31
- == INSTALL:
32
+ ## INSTALL:
32
33
 
33
- $ sudo gem install super_random
34
+ $ gem install super_random
34
35
 
35
- == LICENSE:
36
+ ## LICENSE:
36
37
 
37
38
  (The MIT License)
38
39
 
@@ -1,29 +1,35 @@
1
1
  class SuperRandom
2
2
 
3
+ # http://qrng.anu.edu.au/index.php
4
+ # https://qrng.anu.edu.au/API/api-demo.php
3
5
  def self.quantum(n)
4
6
  s = Net::HTTP.get(URI(
5
7
  "https://qrng.anu.edu.au/API/jsonI.php?length=#{n}&type=uint8"))
6
8
  a = JSON.parse(s)['data']
7
9
  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}
10
+ raise unless a.all?{|i| i.is_a?(Integer) and i.between?(0,255)}
9
11
  return a
10
12
  rescue StandardError
11
13
  warn "quantum (qrng.anu.edu.au) failed."
12
14
  return nil
13
15
  end
14
16
 
17
+ # https://www.random.org/
18
+ # https://www.random.org/integers/
15
19
  def self.atmospheric(n)
16
20
  s = Net::HTTP.get(URI(
17
21
  "https://www.random.org/integers/?num=#{n}&min=0&max=255&col=1&base=10&format=plain&rnd=new"))
18
22
  a = s.strip.split(/\s+/).map{|j|j.to_i}
19
23
  raise unless a.length==n
20
- raise unless a.all?{|i| i>-1 and i<256}
24
+ raise unless a.all?{|i| i.between?(0,255)}
21
25
  return a
22
26
  rescue StandardError
23
27
  warn "atmospheric (www.random.org) failed."
24
28
  return nil
25
29
  end
26
30
 
31
+ # http://random.hd.org/
32
+ # http://random.hd.org/getBits.jsp
27
33
  def self.entropy_pool(n)
28
34
  s = Net::HTTP.get(URI(
29
35
  "http://random.hd.org/getBits.jsp?numBytes=#{n}&type=bin"))
@@ -36,6 +42,7 @@ class SuperRandom
36
42
  return nil
37
43
  end
38
44
 
45
+ # https://www.fourmilab.ch/hotbits/
39
46
  def self.hotbits(n, k='Pseudorandom')
40
47
  s = Net::HTTP.get(URI(
41
48
  "https://www.fourmilab.ch/cgi-bin/Hotbits.api?nbytes=#{n}&fmt=bin&apikey=#{k}"))
@@ -47,6 +54,18 @@ class SuperRandom
47
54
  return nil
48
55
  end
49
56
 
57
+ # http://www.randomnumbers.info
58
+ def self.quantis(n)
59
+ s = Net::HTTP.get(URI(
60
+ "http://www.randomnumbers.info/cgibin/wqrng.cgi?amount=#{n}&limit=255"))
61
+ a = s.scan( /\s\d\d?\d?\b/ ).map{|i| i.to_i}
62
+ raise unless a.length == n and a.all?{|i| i.between?(0,255)}
63
+ return a
64
+ rescue
65
+ warn "quantis (www.randomnumbers.info) failed."
66
+ return nil
67
+ end
68
+
50
69
  attr_accessor :first_timeout, :second_timeout, :nevermind
51
70
  attr_reader :randomness, :services
52
71
 
@@ -62,25 +81,25 @@ class SuperRandom
62
81
  @randomness = 0.0
63
82
  @services = 0
64
83
 
65
- a1 = a2 = a3 = a4 = nil
84
+ a1 = a2 = a3 = a4 = a5 = nil
66
85
 
67
86
  t1 = Thread.new{ a1 = SuperRandom.quantum(n)}
68
87
  t2 = Thread.new{ a2 = SuperRandom.atmospheric(n)}
69
88
  t3 = Thread.new{ a3 = SuperRandom.entropy_pool(n)}
70
89
  t4 = Thread.new{ a4 = SuperRandom.hotbits(n)}
90
+ t5 = Thread.new{ a5 = SuperRandom.quantis(n)}
71
91
 
72
92
  begin
73
93
  Timeout.timeout(@first_timeout) do
74
94
  # Initially, would like to get them all.
75
- t1.join and t2.join and t3.join and t4.join
95
+ t1.join and t2.join and t3.join and t4.join and t5.join
76
96
  end
77
97
  rescue Timeout::Error
78
98
  begin
79
99
  Timeout.timeout(@second_timeout) do
80
100
  # But at this point,
81
101
  # would like to get at least one.
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?)
102
+ while [a1,a2,a3,a4,a5].all?{|a|a.nil?} and [t1,t2,t3,t4,t5].any?{|t|t.alive?}
84
103
  Thread.pass
85
104
  end
86
105
  end
@@ -91,7 +110,7 @@ class SuperRandom
91
110
  end
92
111
 
93
112
  a = n.times.inject([]){|b,i|b.push(SecureRandom.random_number(256))}
94
- [a1, a2, a3, a4].each do |b|
113
+ [a1, a2, a3, a4, a5].each do |b|
95
114
  if b
96
115
  bl = b.length
97
116
  @randomness += bl.to_f/n.to_f
data/lib/super_random.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  class SuperRandom
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
4
4
 
5
5
  # Standard Libraries
metadata CHANGED
@@ -1,26 +1,25 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: super_random
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.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-08-22 00:00:00.000000000 Z
11
+ date: 2019-12-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  You can't get more random than random, but you can try really, really, really hard.
15
15
 
16
- SuperRandom combines four online real random services to create a more perfect random byte.
16
+ SuperRandom combines five online real random services to create a more perfect random byte.
17
17
  email: carlosjhr64@gmail.com
18
18
  executables: []
19
19
  extensions: []
20
- extra_rdoc_files:
21
- - README.rdoc
20
+ extra_rdoc_files: []
22
21
  files:
23
- - README.rdoc
22
+ - README.md
24
23
  - lib/super_random.rb
25
24
  - lib/super_random/super_random.rb
26
25
  homepage: https://github.com/carlosjhr64/super_random
@@ -28,9 +27,7 @@ licenses:
28
27
  - MIT
29
28
  metadata: {}
30
29
  post_install_message:
31
- rdoc_options:
32
- - "--main"
33
- - README.rdoc
30
+ rdoc_options: []
34
31
  require_paths:
35
32
  - lib
36
33
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -44,9 +41,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
44
41
  - !ruby/object:Gem::Version
45
42
  version: '0'
46
43
  requirements:
47
- - 'ruby: ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]'
48
- rubyforge_project:
49
- rubygems_version: 2.6.11
44
+ - 'ruby: ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux]'
45
+ rubygems_version: 3.0.3
50
46
  signing_key:
51
47
  specification_version: 4
52
48
  summary: You can't get more random than random, but you can try really, really, really