quantum_rng 0.1.5 → 0.2.1

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
2
  SHA1:
3
- metadata.gz: 5054e7772ed7a8bea7806318efb18700c5f64490
4
- data.tar.gz: 94f84e8975ea24cfa1f2110599f52d267750b705
3
+ metadata.gz: 975bdbe8908300e96748f410a5de67fc5425fd22
4
+ data.tar.gz: f4cb771f6bcdb79c297c5a65c74996b7e162ac56
5
5
  SHA512:
6
- metadata.gz: 0ea1361b69d4e858c850c3c5b2ecf5d90f410e7f866aab0502c02ef40d1ba721004cf9d0711c205757010d616241cc8ec8a1ff523f517f166dda4e3519047c7f
7
- data.tar.gz: c3d8de5de6a5aa63c7379df34b8105f04cbe7bc9fdbe9395c8bfcba4d878483ae68d81fb9c1352ff2f43a87c640f83955b3de14ac80b291a3355d6e9d6a541b4
6
+ metadata.gz: 0cbad12ff87da8142b494bbc20822da6ca8aa4b574bb3255cb23fe734cc2c64c5b06482f74c2c32e053b09fdbae03f77566d42093d423cc2e1260f47432e720e
7
+ data.tar.gz: 8a5fb05ff8d6781941cf06bb397c96e33981a717b26f464194f0562fb8acb260edf14590c5f270704462b32c2686c321de1be6225907e57c2c1460ff6b2bd802
@@ -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
@@ -1,24 +1,33 @@
1
1
  require 'quantum_rng/version'
2
+ require 'securerandom'
2
3
  require 'net/http'
3
4
  require 'json'
4
5
 
5
6
  # QuantumRNG gets random numbers from the ANU Quantum RNG API.
6
7
  module QuantumRNG
7
- @base = 'http://qrng.anu.edu.au/API/jsonI.php?'
8
-
9
8
  def self.uint8(count = 1)
10
- uri = URI.parse "#{@base}length=#{count}&type=uint8"
11
- parse_api(uri)
9
+ make_request(
10
+ -> { Array.new(count).map { SecureRandom.random_number 255 } },
11
+ length: count,
12
+ type: 'uint8'
13
+ )
12
14
  end
13
15
 
14
16
  def self.uint16(count = 1)
15
- uri = URI.parse "#{@base}length=#{count}&type=uint16"
16
- parse_api(uri)
17
+ make_request(
18
+ -> { Array.new(count).map { SecureRandom.random_number(65_535) } },
19
+ length: count,
20
+ type: 'uint16'
21
+ )
17
22
  end
18
23
 
19
24
  def self.hex16(block_size, count = 1)
20
- uri = URI.parse "#{@base}length=#{count}&type=hex16&size=#{block_size}"
21
- parse_api(uri)
25
+ make_request(
26
+ -> { Array.new(count).map { SecureRandom.hex block_size } },
27
+ length: count,
28
+ type: 'hex16',
29
+ size: block_size
30
+ )
22
31
  end
23
32
 
24
33
  def self.random(count = 1)
@@ -35,12 +44,16 @@ module QuantumRNG
35
44
 
36
45
  private
37
46
 
38
- def self.parse_api(uri)
39
- packet = JSON.parse Net::HTTP.get uri
40
- if packet['success']
41
- packet['data']
47
+ def self.make_request(backup, queries)
48
+ q = URI.encode_www_form(queries)
49
+ uri = URI.parse("http://qrng.anu.edu.au/API/jsonI.php?#{q}")
50
+ packet = JSON.parse(Net::HTTP.get(uri), symbolize_names: true)
51
+ if packet[:success]
52
+ packet[:data]
42
53
  else
43
- fail "[ERROR] #{JSON.pretty_generate(packet)}"
54
+ backup.call
44
55
  end
56
+ rescue
57
+ backup.call
45
58
  end
46
59
  end
@@ -1,4 +1,4 @@
1
1
  # Gem Version
2
2
  module QuantumRng
3
- VERSION = '0.1.5'
3
+ VERSION = '0.2.1'
4
4
  end
@@ -21,4 +21,5 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_development_dependency 'bundler', '~> 1.8'
23
23
  spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'minitest', '~> 5.8'
24
25
  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.2.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: 2015-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
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.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.8'
41
55
  description: Please see http://qrng.anu.edu.au/FAQ.php#api for more information on
42
56
  the bare JSON API, as well as the science behind it.
43
57
  email:
@@ -76,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
90
  version: '0'
77
91
  requirements: []
78
92
  rubyforge_project:
79
- rubygems_version: 2.4.6
93
+ rubygems_version: 2.4.8
80
94
  signing_key:
81
95
  specification_version: 4
82
96
  summary: A random number generator that leverages the ANU Quantum Random Nubmers API.