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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6a6be9de6482f66518e8a72dc0d461d308748fbe
4
- data.tar.gz: c545e0895e9fd61a11b30e33fca187c44673c02b
3
+ metadata.gz: 5054e7772ed7a8bea7806318efb18700c5f64490
4
+ data.tar.gz: 94f84e8975ea24cfa1f2110599f52d267750b705
5
5
  SHA512:
6
- metadata.gz: e4724cfdaf07f674ddf179380101283e7db52e4277ae5b301f8c8032a2648e4265742ee2d7d66fb019367d8b321b0b9232f3dc227475906a2bf82c67ceb6c7b0
7
- data.tar.gz: b748b52492e00eab0ccf98e7a44037e0459cf4385af9608a411b36b5bf0101a9fe3e47d318d8d0f893616a214ff42211a0f856259fe2dc5fe8996049d80a5e14
6
+ metadata.gz: 0ea1361b69d4e858c850c3c5b2ecf5d90f410e7f866aab0502c02ef40d1ba721004cf9d0711c205757010d616241cc8ec8a1ff523f517f166dda4e3519047c7f
7
+ data.tar.gz: c3d8de5de6a5aa63c7379df34b8105f04cbe7bc9fdbe9395c8bfcba4d878483ae68d81fb9c1352ff2f43a87c640f83955b3de14ac80b291a3355d6e9d6a541b4
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ *.gem
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) | Description |
22
- | ------ | :-------------------: | -------------------------------------------- |
23
- | uint8 | count = 1 | `count` numbers between 0 and 255 |
24
- | uint16 | count = 1 | `count` numbers between 0 and 65535 |
25
- | hex16 | block_size, count = 1 | `count` hex numbers of `block_size` bytes |
26
- | random | count = 1 | `count` numbers between 0 and 1, inclusive |
27
- | int | max, count = 1 | `count` integers in the range `[0, max)` |
28
- | float | max, count = 1 | `count` real numbers in the range `[0, 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
@@ -1,2 +1,8 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ end
2
6
 
7
+ desc "Run tests"
8
+ task :default => :test
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "quantum_rng"
5
- require "irb"
3
+ require 'bundler/setup'
4
+ require 'quantum_rng'
5
+ require 'irb'
6
6
  IRB.start
@@ -1,46 +1,46 @@
1
- require "quantum_rng/version"
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 "#{@@base}length=#{count}&type=uint8"
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 "#{@@base}length=#{count}&type=uint16"
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 "#{@@base}length=#{count}&type=hex16&size=#{block_size}"
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
- result = uint16(count).map { | r | r / 65535.0 }
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 { | r | (r * max).to_i }
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 { | r | (r * max).to_f }
33
+ random(count).map { |r| (r * max).to_f }
34
34
  end
35
35
 
36
36
  private
37
- def self.parse_api(uri)
38
- packet = JSON.parse Net::HTTP.get uri
39
- if packet["success"]
40
- rng = packet["data"]
41
- else
42
- raise "[ERROR] #{JSON.pretty_generate(packet)}"
43
- end
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
@@ -1,3 +1,4 @@
1
+ # Gem Version
1
2
  module QuantumRng
2
- VERSION = "0.1.0"
3
+ VERSION = '0.1.5'
3
4
  end
@@ -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 = "quantum_rng"
7
+ spec.name = 'quantum_rng'
8
8
  spec.version = QuantumRng::VERSION
9
- spec.authors = ["Ben Christianson"]
10
- spec.email = ["thhuntertgm@gmail.com"]
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 = "https://github.com/alephtwo/quantum_rng"
15
- spec.license = "MIT"
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 = "exe"
18
+ spec.bindir = 'exe'
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = ["lib"]
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', '~> 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.0
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-16 00:00:00.000000000 Z
11
+ date: 2015-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler