quantum_rng 0.1.5 → 0.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5054e7772ed7a8bea7806318efb18700c5f64490
4
- data.tar.gz: 94f84e8975ea24cfa1f2110599f52d267750b705
2
+ SHA256:
3
+ metadata.gz: 7364063eaff30c32420abee7c5eb092d0ebb56bd236bd4f4b6c617d593f4af45
4
+ data.tar.gz: 28cbb4630a1d148baf47b4de23c5d831d5cbe0c2e74a47ccbd9225df9b3a57a2
5
5
  SHA512:
6
- metadata.gz: 0ea1361b69d4e858c850c3c5b2ecf5d90f410e7f866aab0502c02ef40d1ba721004cf9d0711c205757010d616241cc8ec8a1ff523f517f166dda4e3519047c7f
7
- data.tar.gz: c3d8de5de6a5aa63c7379df34b8105f04cbe7bc9fdbe9395c8bfcba4d878483ae68d81fb9c1352ff2f43a87c640f83955b3de14ac80b291a3355d6e9d6a541b4
6
+ metadata.gz: 92f7ab1762c5cb981da3e508bc386bfb9b9d193f2635d14113344b4b2cc9082f393cbe3c08978e2c04888c9b36f15b7bd68e8d2adbbb9e394e754308d53c8eb2
7
+ data.tar.gz: 3c242a06c2881387e313b507b26a7f94bbee118856fdec60fa8e061d1a2b284a28461d7b230a65904399d7a18bbea2b14f13411fe7f95e0ccda459f7dd2df9d0
data/.rubocop.yml ADDED
@@ -0,0 +1,5 @@
1
+ Metrics/LineLength:
2
+ Exclude:
3
+ - 'quantum_rng.gemspec'
4
+ Metrics/AbcSize:
5
+ Max: 17.15
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015 TODO: Ben Christianson
3
+ Copyright (c) 2015 Ben Christianson
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  A Ruby gem that leverages the [ANU Quantum Random Numbers Server API](http://qrng.anu.edu.au/index.php).
3
3
 
4
4
  # Acknowledgements
5
- This gem exists entirely as an interface to the ANU Quantum Random Numbers API. **All of the heavy lifting is done on their side, and any credit belongs entirely to them.** I have just generalized access to the JSON API.
5
+ This gem exists entirely as an interface to the ANU Quantum Random Numbers API. **All of the heavy lifting is done on their side, and any credit belongs entirely to them.** I have just generalized access to the JSON API.
6
6
  Please give them a visit: [http://photonics.anu.edu.au/qoptics/Research/qrng.php](http://photonics.anu.edu.au/qoptics/Research/qrng.php)
7
7
 
8
8
  ### So, you want random numbers...
@@ -34,7 +34,7 @@ gem 'quantum_rng'
34
34
  Every method returns an array of numbers.
35
35
 
36
36
  ## Errors
37
- * If you are unable to connect to the ANU RNG server for any reason, this gem won't function at all.
37
+ * If you are unable to connect to the ANU RNG server for any reason, this gem will default to similar interactions using `SecureRandom`. In future versions, this will be allowed as a configuration option.
38
38
  * Requesting too many numbers (usually where `count > 1025`) or passing invalid arguments will likely cause a RuntimeError. In future versions, this behavior will be softened.
39
39
 
40
40
  ## Examples
data/Rakefile CHANGED
@@ -4,5 +4,5 @@ Rake::TestTask.new do |t|
4
4
  t.libs << 'test'
5
5
  end
6
6
 
7
- desc "Run tests"
8
- task :default => :test
7
+ desc 'Run tests'
8
+ task default: :test
@@ -1,4 +1,4 @@
1
1
  # Gem Version
2
- module QuantumRng
3
- VERSION = '0.1.5'
2
+ module QuantumRNG
3
+ VERSION = '0.3.1'.freeze
4
4
  end
data/lib/quantum_rng.rb CHANGED
@@ -1,24 +1,34 @@
1
1
  require 'quantum_rng/version'
2
+ require 'securerandom'
2
3
  require 'net/http'
3
4
  require 'json'
5
+ require 'curb'
4
6
 
5
7
  # QuantumRNG gets random numbers from the ANU Quantum RNG API.
6
8
  module QuantumRNG
7
- @base = 'http://qrng.anu.edu.au/API/jsonI.php?'
8
-
9
9
  def self.uint8(count = 1)
10
- uri = URI.parse "#{@base}length=#{count}&type=uint8"
11
- parse_api(uri)
10
+ make_request(
11
+ -> { Array.new(count).map { SecureRandom.random_number 255 } },
12
+ length: count,
13
+ type: 'uint8'
14
+ )
12
15
  end
13
16
 
14
17
  def self.uint16(count = 1)
15
- uri = URI.parse "#{@base}length=#{count}&type=uint16"
16
- parse_api(uri)
18
+ make_request(
19
+ -> { Array.new(count).map { SecureRandom.random_number 65_535 } },
20
+ length: count,
21
+ type: 'uint16'
22
+ )
17
23
  end
18
24
 
19
25
  def self.hex16(block_size, count = 1)
20
- uri = URI.parse "#{@base}length=#{count}&type=hex16&size=#{block_size}"
21
- parse_api(uri)
26
+ make_request(
27
+ -> { Array.new(count).map { SecureRandom.hex block_size } },
28
+ length: count,
29
+ type: 'hex16',
30
+ size: block_size
31
+ )
22
32
  end
23
33
 
24
34
  def self.random(count = 1)
@@ -33,14 +43,18 @@ module QuantumRNG
33
43
  random(count).map { |r| (r * max).to_f }
34
44
  end
35
45
 
36
- private
46
+ private_class_method
37
47
 
38
- def self.parse_api(uri)
39
- packet = JSON.parse Net::HTTP.get uri
40
- if packet['success']
41
- packet['data']
48
+ def self.make_request(backup, queries)
49
+ q = URI.encode_www_form(queries)
50
+ data = Curl.get('http://qrng.anu.edu.au/API/jsonI.php', q).body
51
+ packet = JSON.parse(data, symbolize_names: true)
52
+ if packet[:success]
53
+ packet[:data]
42
54
  else
43
- fail "[ERROR] #{JSON.pretty_generate(packet)}"
55
+ backup.call
44
56
  end
57
+ rescue
58
+ backup.call
45
59
  end
46
60
  end
data/quantum_rng.gemspec CHANGED
@@ -5,12 +5,12 @@ require 'quantum_rng/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'quantum_rng'
8
- spec.version = QuantumRng::VERSION
8
+ spec.version = QuantumRNG::VERSION
9
9
  spec.authors = ['Ben Christianson']
10
10
  spec.email = ['thhuntertgm@gmail.com']
11
11
 
12
- spec.summary = %q{A random number generator that leverages the ANU Quantum Random Nubmers API.}
13
- spec.description = %q{Please see http://qrng.anu.edu.au/FAQ.php#api for more information on the bare JSON API, as well as the science behind it.}
12
+ spec.summary = 'A random number generator that leverages the ANU Quantum Random Nubmers API.'
13
+ spec.description = 'Please see http://qrng.anu.edu.au/FAQ.php#api for more information on the bare JSON API, as well as the science behind it.'
14
14
  spec.homepage = 'https://github.com/alephtwo/quantum_rng'
15
15
  spec.license = 'MIT'
16
16
 
@@ -19,6 +19,9 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ['lib']
21
21
 
22
- spec.add_development_dependency 'bundler', '~> 1.8'
23
- spec.add_development_dependency 'rake', '~> 10.0'
22
+ spec.add_development_dependency 'bundler', '~> 2.2.28'
23
+ spec.add_development_dependency 'rake', '~> 13.0.6'
24
+ spec.add_development_dependency 'minitest', '~> 5.14.4'
25
+
26
+ spec.add_dependency 'curb', '~> 0.9.11'
24
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quantum_rng
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Christianson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-03-24 00:00:00.000000000 Z
11
+ date: 2021-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,28 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.8'
19
+ version: 2.2.28
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.8'
26
+ version: 2.2.28
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: 13.0.6
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: 13.0.6
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 5.14.4
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 5.14.4
55
+ - !ruby/object:Gem::Dependency
56
+ name: curb
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.11
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.9.11
41
69
  description: Please see http://qrng.anu.edu.au/FAQ.php#api for more information on
42
70
  the bare JSON API, as well as the science behind it.
43
71
  email:
@@ -47,6 +75,7 @@ extensions: []
47
75
  extra_rdoc_files: []
48
76
  files:
49
77
  - ".gitignore"
78
+ - ".rubocop.yml"
50
79
  - Gemfile
51
80
  - LICENSE.txt
52
81
  - README.md
@@ -75,8 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
104
  - !ruby/object:Gem::Version
76
105
  version: '0'
77
106
  requirements: []
78
- rubyforge_project:
79
- rubygems_version: 2.4.6
107
+ rubygems_version: 3.2.3
80
108
  signing_key:
81
109
  specification_version: 4
82
110
  summary: A random number generator that leverages the ANU Quantum Random Nubmers API.