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 +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +2 -2
- data/lib/quantum_rng.rb +26 -13
- data/lib/quantum_rng/version.rb +1 -1
- data/quantum_rng.gemspec +1 -0
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 975bdbe8908300e96748f410a5de67fc5425fd22
|
4
|
+
data.tar.gz: f4cb771f6bcdb79c297c5a65c74996b7e162ac56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0cbad12ff87da8142b494bbc20822da6ca8aa4b574bb3255cb23fe734cc2c64c5b06482f74c2c32e053b09fdbae03f77566d42093d423cc2e1260f47432e720e
|
7
|
+
data.tar.gz: 8a5fb05ff8d6781941cf06bb397c96e33981a717b26f464194f0562fb8acb260edf14590c5f270704462b32c2686c321de1be6225907e57c2c1460ff6b2bd802
|
data/LICENSE.txt
CHANGED
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
|
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/lib/quantum_rng.rb
CHANGED
@@ -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
|
-
|
11
|
-
|
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
|
-
|
16
|
-
|
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
|
-
|
21
|
-
|
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.
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
54
|
+
backup.call
|
44
55
|
end
|
56
|
+
rescue
|
57
|
+
backup.call
|
45
58
|
end
|
46
59
|
end
|
data/lib/quantum_rng/version.rb
CHANGED
data/quantum_rng.gemspec
CHANGED
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
|
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-
|
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.
|
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.
|