quantum_rng 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6a6be9de6482f66518e8a72dc0d461d308748fbe
4
+ data.tar.gz: c545e0895e9fd61a11b30e33fca187c44673c02b
5
+ SHA512:
6
+ metadata.gz: e4724cfdaf07f674ddf179380101283e7db52e4277ae5b301f8c8032a2648e4265742ee2d7d66fb019367d8b321b0b9232f3dc227475906a2bf82c67ceb6c7b0
7
+ data.tar.gz: b748b52492e00eab0ccf98e7a44037e0459cf4385af9608a411b36b5bf0101a9fe3e47d318d8d0f893616a214ff42211a0f856259fe2dc5fe8996049d80a5e14
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in quantum_rng.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 TODO: Ben Christianson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # QuantumRNG
2
+ A Ruby gem that leverages the ANU Quantum Random Numbers API
3
+
4
+ ### So, you want random numbers...
5
+ Computers are great at creating pseudorandom numbers, but true randomness requires a little bit more effort.
6
+
7
+ That's where the fine folks at the [ANU Quantum Random Numbers Server](http://qrng.anu.edu.au/index.php) come in. They've provided a handy JSON API for accessing what they guess are truly random numbers. You can read more about the science behind this and why they believe they've achieved true randomness at their site.
8
+
9
+ ## Installation
10
+ ```
11
+ gem install quantum_rng
12
+ ```
13
+
14
+ If you're using Bundler, include the gem in your `Gemfile`:
15
+ ```
16
+ gem 'quantum_rng'
17
+ ```
18
+
19
+ ## Usage
20
+
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)` |
29
+
30
+ Every method returns an array of numbers.
31
+
32
+ ## Errors
33
+ * If you are unable to connect to the ANU RNG server for any reason, this gem won't function at all.
34
+ * 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.
35
+
36
+ ## Examples
37
+ ```ruby
38
+ # A single random uint8
39
+ QuantumRNG.uint8
40
+ # 5 random uint8
41
+ QuantumRNG.uint8(5)
42
+
43
+ # A single random uint16
44
+ QuantumRNG.uint16
45
+ # 5 random uint16
46
+ QuantumRNG.uint16(5)
47
+
48
+ # A single 1-byte hex number
49
+ QuantumRNG.hex16(1)
50
+ # 5 random 1-byte hex numbers
51
+ QuantumRNG.hex16(1, 5)
52
+
53
+ # A single random between 0 and 1, inclusive
54
+ QuantumRNG.random
55
+ # 5 randoms between 0 and 1, inclusive
56
+ QuantumRNG.random(5)
57
+
58
+ # A single random int less than 100
59
+ QuantumRNG.int(100)
60
+ # 5 ints less than 100
61
+ QuantumRNG.int(100, 5)
62
+
63
+ # A single random float less than 100
64
+ QuantumRNG.float(100)
65
+ # 5 random floats less than 100
66
+ QuantumRNG.float(100, 5)
67
+ ```
68
+
69
+ # TODO
70
+ Future versions will include better error handling.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/console ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "quantum_rng"
5
+ require "irb"
6
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,5 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
@@ -0,0 +1,46 @@
1
+ require "quantum_rng/version"
2
+ require 'net/http'
3
+ require 'json'
4
+
5
+ module QuantumRNG
6
+
7
+ @@base = "http://qrng.anu.edu.au/API/jsonI.php?"
8
+
9
+ def self.uint8(count = 1)
10
+ uri = URI.parse "#{@@base}length=#{count}&type=uint8"
11
+ parse_api(uri)
12
+ end
13
+
14
+ def self.uint16(count = 1)
15
+ uri = URI.parse "#{@@base}length=#{count}&type=uint16"
16
+ parse_api(uri)
17
+ end
18
+
19
+ def self.hex16(block_size, count = 1)
20
+ uri = URI.parse "#{@@base}length=#{count}&type=hex16&size=#{block_size}"
21
+ parse_api(uri)
22
+ end
23
+
24
+ def self.random(count = 1)
25
+ result = uint16(count).map { | r | r / 65535.0 }
26
+ end
27
+
28
+ def self.int(max, count = 1)
29
+ random(count).map { | r | (r * max).to_i }
30
+ end
31
+
32
+ def self.float(max, count = 1)
33
+ random(count).map { | r | (r * max).to_f }
34
+ end
35
+
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
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module QuantumRng
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'quantum_rng/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "quantum_rng"
8
+ spec.version = QuantumRng::VERSION
9
+ spec.authors = ["Ben Christianson"]
10
+ spec.email = ["thhuntertgm@gmail.com"]
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.}
14
+ spec.homepage = "https://github.com/alephtwo/quantum_rng"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.8"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: quantum_rng
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ben Christianson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-03-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Please see http://qrng.anu.edu.au/FAQ.php#api for more information on
42
+ the bare JSON API, as well as the science behind it.
43
+ email:
44
+ - thhuntertgm@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/console
55
+ - bin/setup
56
+ - lib/quantum_rng.rb
57
+ - lib/quantum_rng/version.rb
58
+ - quantum_rng.gemspec
59
+ homepage: https://github.com/alephtwo/quantum_rng
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.4.6
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: A random number generator that leverages the ANU Quantum Random Nubmers API.
83
+ test_files: []