quantum_rng 0.1.0 → 0.1.5
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/.gitignore +1 -0
- data/README.md +14 -10
- data/Rakefile +7 -1
- data/bin/console +3 -3
- data/lib/quantum_rng.rb +18 -18
- data/lib/quantum_rng/version.rb +2 -1
- data/quantum_rng.gemspec +9 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5054e7772ed7a8bea7806318efb18700c5f64490
|
4
|
+
data.tar.gz: 94f84e8975ea24cfa1f2110599f52d267750b705
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ea1361b69d4e858c850c3c5b2ecf5d90f410e7f866aab0502c02ef40d1ba721004cf9d0711c205757010d616241cc8ec8a1ff523f517f166dda4e3519047c7f
|
7
|
+
data.tar.gz: c3d8de5de6a5aa63c7379df34b8105f04cbe7bc9fdbe9395c8bfcba4d878483ae68d81fb9c1352ff2f43a87c640f83955b3de14ac80b291a3355d6e9d6a541b4
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# QuantumRNG
|
2
|
-
A Ruby gem that leverages the ANU Quantum Random Numbers API
|
2
|
+
A Ruby gem that leverages the [ANU Quantum Random Numbers Server API](http://qrng.anu.edu.au/index.php).
|
3
|
+
|
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.
|
6
|
+
Please give them a visit: [http://photonics.anu.edu.au/qoptics/Research/qrng.php](http://photonics.anu.edu.au/qoptics/Research/qrng.php)
|
3
7
|
|
4
8
|
### So, you want random numbers...
|
5
9
|
Computers are great at creating pseudorandom numbers, but true randomness requires a little bit more effort.
|
@@ -18,14 +22,14 @@ gem 'quantum_rng'
|
|
18
22
|
|
19
23
|
## Usage
|
20
24
|
|
21
|
-
| Method | Argument(s)
|
22
|
-
| ------ |
|
23
|
-
| uint8 | count = 1
|
24
|
-
| uint16 | count = 1
|
25
|
-
| hex16 | block_size
|
26
|
-
| random | count = 1
|
27
|
-
| int | max
|
28
|
-
| float | max
|
25
|
+
| Method | Argument(s) | Description |
|
26
|
+
| ------ | :-----------------------: | ----------------------------------------------- |
|
27
|
+
| uint8 | `count = 1` | `count` integers between 0 and 255 |
|
28
|
+
| uint16 | `count = 1` | `count` integers between 0 and 65535 |
|
29
|
+
| hex16 | `block_size`, `count = 1` | `count` hex numbers of `block_size` bytes |
|
30
|
+
| random | `count = 1` | `count` real numbers between 0 and 1, inclusive |
|
31
|
+
| int | `max`, `count = 1` | `count` integers in the range `[0, max)` |
|
32
|
+
| float | `max`, `count = 1` | `count` real numbers in the range `[0, max)` |
|
29
33
|
|
30
34
|
Every method returns an array of numbers.
|
31
35
|
|
@@ -67,4 +71,4 @@ Every method returns an array of numbers.
|
|
67
71
|
```
|
68
72
|
|
69
73
|
# TODO
|
70
|
-
Future versions will include better error handling.
|
74
|
+
Future versions will include better error handling.
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
data/lib/quantum_rng.rb
CHANGED
@@ -1,46 +1,46 @@
|
|
1
|
-
require
|
1
|
+
require 'quantum_rng/version'
|
2
2
|
require 'net/http'
|
3
3
|
require 'json'
|
4
4
|
|
5
|
+
# QuantumRNG gets random numbers from the ANU Quantum RNG API.
|
5
6
|
module QuantumRNG
|
6
|
-
|
7
|
-
@@base = "http://qrng.anu.edu.au/API/jsonI.php?"
|
7
|
+
@base = 'http://qrng.anu.edu.au/API/jsonI.php?'
|
8
8
|
|
9
9
|
def self.uint8(count = 1)
|
10
|
-
uri = URI.parse "#{
|
10
|
+
uri = URI.parse "#{@base}length=#{count}&type=uint8"
|
11
11
|
parse_api(uri)
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.uint16(count = 1)
|
15
|
-
uri = URI.parse "#{
|
15
|
+
uri = URI.parse "#{@base}length=#{count}&type=uint16"
|
16
16
|
parse_api(uri)
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.hex16(block_size, count = 1)
|
20
|
-
uri = URI.parse "#{
|
20
|
+
uri = URI.parse "#{@base}length=#{count}&type=hex16&size=#{block_size}"
|
21
21
|
parse_api(uri)
|
22
22
|
end
|
23
23
|
|
24
24
|
def self.random(count = 1)
|
25
|
-
|
25
|
+
uint16(count).map { |r| r / 65_535.0 }
|
26
26
|
end
|
27
27
|
|
28
28
|
def self.int(max, count = 1)
|
29
|
-
random(count).map { |
|
29
|
+
random(count).map { |r| (r * max).to_i }
|
30
30
|
end
|
31
31
|
|
32
32
|
def self.float(max, count = 1)
|
33
|
-
random(count).map { |
|
33
|
+
random(count).map { |r| (r * max).to_f }
|
34
34
|
end
|
35
35
|
|
36
36
|
private
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
rng
|
37
|
+
|
38
|
+
def self.parse_api(uri)
|
39
|
+
packet = JSON.parse Net::HTTP.get uri
|
40
|
+
if packet['success']
|
41
|
+
packet['data']
|
42
|
+
else
|
43
|
+
fail "[ERROR] #{JSON.pretty_generate(packet)}"
|
45
44
|
end
|
46
|
-
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/quantum_rng/version.rb
CHANGED
data/quantum_rng.gemspec
CHANGED
@@ -4,21 +4,21 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'quantum_rng/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'quantum_rng'
|
8
8
|
spec.version = QuantumRng::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Ben Christianson']
|
10
|
+
spec.email = ['thhuntertgm@gmail.com']
|
11
11
|
|
12
12
|
spec.summary = %q{A random number generator that leverages the ANU Quantum Random Nubmers API.}
|
13
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.}
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
14
|
+
spec.homepage = 'https://github.com/alephtwo/quantum_rng'
|
15
|
+
spec.license = 'MIT'
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
-
spec.bindir =
|
18
|
+
spec.bindir = 'exe'
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
-
spec.require_paths = [
|
20
|
+
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.8'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
24
|
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.
|
4
|
+
version: 0.1.5
|
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-
|
11
|
+
date: 2015-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|