random_outcome 0.1.0 → 0.2.0

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: ec01216c257498d7ec663d0cb3bb99868723eb17
4
- data.tar.gz: 4ba6c9d3626524b12af29344d17194fce7943344
3
+ metadata.gz: 55ba3259ce599dfe1c93d485cea7c63d2e46c0e6
4
+ data.tar.gz: a3ced0376ce6fa19f717baf236402739a33d33e9
5
5
  SHA512:
6
- metadata.gz: 483bc08406ad70ce1d7ff93a2d3fb793ae3259977bfc2f03fc71e46122787543b5fbc8a748491013ab65cf9a6702edaba5b2841f2af33405ad0b561b39e4d706
7
- data.tar.gz: 374f8fb4809a969595ca9f9552a5e0d7259d575eb4c159458eeaa54f429ab96c6428446979c1fa8425fa64fd8bce9401302e5c2e310a3e7c0a00a5861a7b9dab
6
+ metadata.gz: 581d3739946ff9757f15ff806cc9780bf7b9d745cedf1d9149fb29fddaf7f083c32dbb9fba8bfbd09e7068ef11a641bb62afc4d5e4f6fb3afe269ebbc9d3522e
7
+ data.tar.gz: c715d79e2d6a8aca38639bb0a11240f1feee34ce15a7fd4b24df259dabc8a50d67047f2d02e64df50807ad20693711c795ebc1d39c727e9d8874f3d80befe5a4
data/.gemrelease ADDED
@@ -0,0 +1,2 @@
1
+ bump:
2
+ tag: true
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /.idea/
10
+ /spec/examples.txt
data/.rspec CHANGED
@@ -1 +1,2 @@
1
+ --format documentation
1
2
  --color
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ random_outcome
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.3.1
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2
5
+ - 2.1
6
+ - 2.0
7
+ - 1.9.3
8
+ - 1.9.2
9
+ - 1.8.7
10
+ before_install: gem install bundler -v 1.12.5
data/Gemfile CHANGED
@@ -1,16 +1,4 @@
1
- source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
1
+ source 'https://rubygems.org'
5
2
 
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
8
- group :development do
9
- gem "rspec", "~> 2.8.0"
10
- gem "yard", "~> 0.7"
11
- gem "rdoc", "~> 3.12"
12
- gem "bundler", "~> 1.0"
13
- gem "jeweler", "~> 1.8.7"
14
- end
15
-
16
- gem "activesupport"
3
+ # Specify your gem's dependencies in random_outcome.gemspec
4
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,78 +1,49 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ random_outcome (0.2.0)
5
+ activesupport (= 5.0.0.1)
6
+
1
7
  GEM
2
- remote: http://rubygems.org/
8
+ remote: https://rubygems.org/
3
9
  specs:
4
- activesupport (4.0.0)
5
- i18n (~> 0.6, >= 0.6.4)
6
- minitest (~> 4.2)
7
- multi_json (~> 1.3)
10
+ activesupport (5.0.0.1)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (~> 0.7)
13
+ minitest (~> 5.1)
14
+ tzinfo (~> 1.1)
15
+ concurrent-ruby (1.0.2)
16
+ diff-lcs (1.2.5)
17
+ i18n (0.7.0)
18
+ minitest (5.9.0)
19
+ rake (11.2.2)
20
+ rspec (3.5.0)
21
+ rspec-core (~> 3.5.0)
22
+ rspec-expectations (~> 3.5.0)
23
+ rspec-mocks (~> 3.5.0)
24
+ rspec-core (3.5.2)
25
+ rspec-support (~> 3.5.0)
26
+ rspec-expectations (3.5.0)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.5.0)
29
+ rspec-mocks (3.5.0)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.5.0)
32
+ rspec-support (3.5.0)
33
+ thread_safe (0.3.5)
34
+ tzinfo (1.2.2)
8
35
  thread_safe (~> 0.1)
9
- tzinfo (~> 0.3.37)
10
- addressable (2.3.5)
11
- atomic (1.1.14)
12
- builder (3.2.2)
13
- diff-lcs (1.1.3)
14
- faraday (0.8.8)
15
- multipart-post (~> 1.2.0)
16
- git (1.2.6)
17
- github_api (0.10.1)
18
- addressable
19
- faraday (~> 0.8.1)
20
- hashie (>= 1.2)
21
- multi_json (~> 1.4)
22
- nokogiri (~> 1.5.2)
23
- oauth2
24
- hashie (2.0.5)
25
- highline (1.6.20)
26
- httpauth (0.2.0)
27
- i18n (0.6.5)
28
- jeweler (1.8.8)
29
- builder
30
- bundler (~> 1.0)
31
- git (>= 1.2.5)
32
- github_api (= 0.10.1)
33
- highline (>= 1.6.15)
34
- nokogiri (= 1.5.10)
35
- rake
36
- rdoc
37
- json (1.8.1)
38
- jwt (0.1.8)
39
- multi_json (>= 1.5)
40
- minitest (4.7.5)
41
- multi_json (1.8.2)
42
- multi_xml (0.5.5)
43
- multipart-post (1.2.0)
44
- nokogiri (1.5.10)
45
- oauth2 (0.9.2)
46
- faraday (~> 0.8)
47
- httpauth (~> 0.2)
48
- jwt (~> 0.1.4)
49
- multi_json (~> 1.0)
50
- multi_xml (~> 0.5)
51
- rack (~> 1.2)
52
- rack (1.5.2)
53
- rake (10.1.0)
54
- rdoc (3.12.2)
55
- json (~> 1.4)
56
- rspec (2.8.0)
57
- rspec-core (~> 2.8.0)
58
- rspec-expectations (~> 2.8.0)
59
- rspec-mocks (~> 2.8.0)
60
- rspec-core (2.8.0)
61
- rspec-expectations (2.8.0)
62
- diff-lcs (~> 1.1.2)
63
- rspec-mocks (2.8.0)
64
- thread_safe (0.1.3)
65
- atomic
66
- tzinfo (0.3.38)
67
- yard (0.8.7.2)
36
+ yard (0.9.5)
68
37
 
69
38
  PLATFORMS
70
39
  ruby
71
40
 
72
41
  DEPENDENCIES
73
- activesupport
74
- bundler (~> 1.0)
75
- jeweler (~> 1.8.7)
76
- rdoc (~> 3.12)
77
- rspec (~> 2.8.0)
78
- yard (~> 0.7)
42
+ bundler (~> 1.12)
43
+ rake (~> 11.2.2)
44
+ random_outcome!
45
+ rspec (~> 3.5.0)
46
+ yard (~> 0.9.5)
47
+
48
+ BUNDLED WITH
49
+ 1.12.5
data/LICENSE.txt CHANGED
@@ -1,20 +1,21 @@
1
- Copyright (c) 2013 Nigel Lowry
1
+ The MIT License (MIT)
2
2
 
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
3
+ Copyright (c) 2016 Nigel Lowry
10
4
 
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
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:
13
11
 
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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,41 @@
1
+ # Random_outcome
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/random_outcome`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'random_outcome'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install random_outcome
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/random_outcome.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile CHANGED
@@ -1,42 +1,6 @@
1
- # encoding: utf-8
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
2
3
 
3
- require 'rubygems'
4
- require 'bundler'
5
- begin
6
- Bundler.setup(:default, :development)
7
- rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts "Run `bundle install` to install missing gems"
10
- exit e.status_code
11
- end
12
- require 'rake'
13
-
14
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
- gem.name = "random_outcome"
18
- gem.homepage = "http://github.com/nigel-lowry/random_outcome"
19
- gem.license = "MIT"
20
- gem.summary = %Q{Small Ruby gem for generating outcomes with specified probabilities}
21
- gem.description = %Q{Generates outcomes with specified probabilities which could be useful for gaming. Uses the wheel of fortune method.}
22
- gem.email = "nigel-lowry@ultra.eclipse.co.uk"
23
- gem.authors = ["Nigel Lowry"]
24
- # dependencies defined in Gemfile
25
- end
26
- Jeweler::RubygemsDotOrgTasks.new
27
-
28
- require 'rspec/core'
29
- require 'rspec/core/rake_task'
30
- RSpec::Core::RakeTask.new(:spec) do |spec|
31
- spec.pattern = FileList['spec/**/*_spec.rb']
32
- end
33
-
34
- RSpec::Core::RakeTask.new(:rcov) do |spec|
35
- spec.pattern = 'spec/**/*_spec.rb'
36
- spec.rcov = true
37
- end
4
+ RSpec::Core::RakeTask.new(:spec)
38
5
 
39
6
  task :default => :spec
40
-
41
- require 'yard'
42
- YARD::Rake::YardocTask.new
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "random_outcome"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ require "random_outcome/version"
2
+
3
+ module RandomOutcome
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,63 @@
1
+ require 'active_support/all'
2
+
3
+ module RandomOutcome
4
+ # Generates outcomes with specified probabilities
5
+ class Simulator
6
+
7
+ # creates a new Simulator which will return the desired outcomes with the given probability
8
+ # @param outcome_to_probability [Hash<Symbol, Number>] hash of outcomes to their probability (represented as
9
+ # numbers between zero and one)
10
+ # @note raises errors if there is only one possible outcome (why bother using this if there's only one
11
+ # outcome?), if the probabilities don't total one (use Rationals if this proves problematic with rounding) or
12
+ # if any of the outcomes are impossible (why include them if they can never happen?)
13
+ def initialize outcome_to_probability
14
+ raise_if_dont_have_many_outcomes outcome_to_probability
15
+ raise_if_probabilities_total_isnt_one outcome_to_probability
16
+ raise_if_have_any_impossible_outcomes outcome_to_probability
17
+ raise_if_have_any_negative_probabilities outcome_to_probability
18
+ @probability_range_to_outcome = probability_range_to_outcome outcome_to_probability
19
+ end
20
+
21
+ # generate an outcome with the initialised probabilities
22
+ # @return [Symbol] symbol for outcome
23
+ def outcome
24
+ num = random_float_including_zero_and_excluding_one # don't inline
25
+ @probability_range_to_outcome.detect { |probability_range, _| num.in? probability_range }.last
26
+ end
27
+
28
+ private
29
+
30
+ def raise_if_dont_have_many_outcomes outcome_to_probability
31
+ raise 'needs many outcomes' unless outcome_to_probability.many?
32
+ end
33
+
34
+ def raise_if_probabilities_total_isnt_one outcome_to_probability
35
+ raise "probabilities don't total one" unless outcome_to_probability.values.sum == 1.0
36
+ end
37
+
38
+ def raise_if_have_any_impossible_outcomes outcome_to_probability
39
+ raise 'have an impossible outcome' if outcome_to_probability.has_value? 0.0
40
+ end
41
+
42
+ def raise_if_have_any_negative_probabilities outcome_to_probability
43
+ raise 'have negative probability' if outcome_to_probability.values.any? { |probability| probability < 0.0 }
44
+ end
45
+
46
+ def random_float_including_zero_and_excluding_one
47
+ rand
48
+ end
49
+
50
+ def probability_range_to_outcome outcome_to_probability
51
+ range_to_outcome = {}
52
+ lower_bound = 0.0
53
+
54
+ outcome_to_probability.each do |outcome, probability|
55
+ upper_bound = lower_bound + probability
56
+ range_to_outcome.store lower_bound...upper_bound, outcome
57
+ lower_bound = upper_bound
58
+ end
59
+
60
+ range_to_outcome
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,3 @@
1
+ module RandomOutcome
2
+ VERSION = "0.2.0"
3
+ end
@@ -1,69 +1,28 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
- # stub: random_outcome 0.1.0 ruby lib
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'random_outcome/version'
6
5
 
7
- Gem::Specification.new do |s|
8
- s.name = "random_outcome"
9
- s.version = "0.1.0"
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "random_outcome"
8
+ spec.version = RandomOutcome::VERSION
9
+ spec.authors = ["Nigel Lowry"]
10
+ spec.email = ["nigel-lowry@ultra.eclipse.co.uk"]
10
11
 
11
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
- s.authors = ["Nigel Lowry"]
13
- s.date = "2013-10-27"
14
- s.description = "Generates outcomes with specified probabilities which could be useful for gaming. Uses the wheel of fortune method."
15
- s.email = "nigel-lowry@ultra.eclipse.co.uk"
16
- s.extra_rdoc_files = [
17
- "LICENSE.txt",
18
- "README.rdoc"
19
- ]
20
- s.files = [
21
- ".document",
22
- ".rspec",
23
- ".rvmrc",
24
- "Gemfile",
25
- "Gemfile.lock",
26
- "LICENSE.txt",
27
- "README.rdoc",
28
- "Rakefile",
29
- "VERSION",
30
- "lib/simulator.rb",
31
- "random_outcome.gemspec",
32
- "spec/simulator_spec.rb",
33
- "spec/spec_helper.rb",
34
- "spec/support/matchers/give_the_outcome.rb"
35
- ]
36
- s.homepage = "http://github.com/nigel-lowry/random_outcome"
37
- s.licenses = ["MIT"]
38
- s.require_paths = ["lib"]
39
- s.rubygems_version = "2.1.5"
40
- s.summary = "Small Ruby gem for generating outcomes with specified probabilities"
12
+ spec.summary = %q{Small gem for generating random outcomes.}
13
+ spec.description = %q{Useful or gaming.}
14
+ spec.homepage = "https://github.com/nigel-lowry/random_outcome"
15
+ spec.license = "MIT"
41
16
 
42
- if s.respond_to? :specification_version then
43
- s.specification_version = 4
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"]
44
21
 
45
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
- s.add_runtime_dependency(%q<activesupport>, [">= 0"])
47
- s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
48
- s.add_development_dependency(%q<yard>, ["~> 0.7"])
49
- s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
50
- s.add_development_dependency(%q<bundler>, ["~> 1.0"])
51
- s.add_development_dependency(%q<jeweler>, ["~> 1.8.7"])
52
- else
53
- s.add_dependency(%q<activesupport>, [">= 0"])
54
- s.add_dependency(%q<rspec>, ["~> 2.8.0"])
55
- s.add_dependency(%q<yard>, ["~> 0.7"])
56
- s.add_dependency(%q<rdoc>, ["~> 3.12"])
57
- s.add_dependency(%q<bundler>, ["~> 1.0"])
58
- s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
59
- end
60
- else
61
- s.add_dependency(%q<activesupport>, [">= 0"])
62
- s.add_dependency(%q<rspec>, ["~> 2.8.0"])
63
- s.add_dependency(%q<yard>, ["~> 0.7"])
64
- s.add_dependency(%q<rdoc>, ["~> 3.12"])
65
- s.add_dependency(%q<bundler>, ["~> 1.0"])
66
- s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
67
- end
68
- end
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 11.2.2"
24
+ spec.add_development_dependency "yard", "~> 0.9.5"
25
+ spec.add_development_dependency "rspec", "~> 3.5.0"
69
26
 
27
+ spec.add_dependency "activesupport", "5.0.0.1"
28
+ end
metadata CHANGED
@@ -1,123 +1,110 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: random_outcome
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nigel Lowry
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2013-10-27 00:00:00.000000000 Z
11
+ date: 2016-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: activesupport
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - '>='
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - '>='
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: rspec
14
+ name: bundler
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
- - - ~>
17
+ - - "~>"
32
18
  - !ruby/object:Gem::Version
33
- version: 2.8.0
19
+ version: '1.12'
34
20
  type: :development
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
- - - ~>
24
+ - - "~>"
39
25
  - !ruby/object:Gem::Version
40
- version: 2.8.0
26
+ version: '1.12'
41
27
  - !ruby/object:Gem::Dependency
42
- name: yard
28
+ name: rake
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
- - - ~>
31
+ - - "~>"
46
32
  - !ruby/object:Gem::Version
47
- version: '0.7'
33
+ version: 11.2.2
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - ~>
38
+ - - "~>"
53
39
  - !ruby/object:Gem::Version
54
- version: '0.7'
40
+ version: 11.2.2
55
41
  - !ruby/object:Gem::Dependency
56
- name: rdoc
42
+ name: yard
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
- - - ~>
45
+ - - "~>"
60
46
  - !ruby/object:Gem::Version
61
- version: '3.12'
47
+ version: 0.9.5
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
- - - ~>
52
+ - - "~>"
67
53
  - !ruby/object:Gem::Version
68
- version: '3.12'
54
+ version: 0.9.5
69
55
  - !ruby/object:Gem::Dependency
70
- name: bundler
56
+ name: rspec
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
- - - ~>
59
+ - - "~>"
74
60
  - !ruby/object:Gem::Version
75
- version: '1.0'
61
+ version: 3.5.0
76
62
  type: :development
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
- - - ~>
66
+ - - "~>"
81
67
  - !ruby/object:Gem::Version
82
- version: '1.0'
68
+ version: 3.5.0
83
69
  - !ruby/object:Gem::Dependency
84
- name: jeweler
70
+ name: activesupport
85
71
  requirement: !ruby/object:Gem::Requirement
86
72
  requirements:
87
- - - ~>
73
+ - - '='
88
74
  - !ruby/object:Gem::Version
89
- version: 1.8.7
90
- type: :development
75
+ version: 5.0.0.1
76
+ type: :runtime
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
94
- - - ~>
80
+ - - '='
95
81
  - !ruby/object:Gem::Version
96
- version: 1.8.7
97
- description: Generates outcomes with specified probabilities which could be useful
98
- for gaming. Uses the wheel of fortune method.
99
- email: nigel-lowry@ultra.eclipse.co.uk
82
+ version: 5.0.0.1
83
+ description: Useful or gaming.
84
+ email:
85
+ - nigel-lowry@ultra.eclipse.co.uk
100
86
  executables: []
101
87
  extensions: []
102
- extra_rdoc_files:
103
- - LICENSE.txt
104
- - README.rdoc
88
+ extra_rdoc_files: []
105
89
  files:
106
- - .document
107
- - .rspec
108
- - .rvmrc
90
+ - ".gemrelease"
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".ruby-gemset"
94
+ - ".ruby-version"
95
+ - ".travis.yml"
109
96
  - Gemfile
110
97
  - Gemfile.lock
111
98
  - LICENSE.txt
112
- - README.rdoc
99
+ - README.md
113
100
  - Rakefile
114
- - VERSION
115
- - lib/simulator.rb
101
+ - bin/console
102
+ - bin/setup
103
+ - lib/random_outcome.rb
104
+ - lib/random_outcome/simulator.rb
105
+ - lib/random_outcome/version.rb
116
106
  - random_outcome.gemspec
117
- - spec/simulator_spec.rb
118
- - spec/spec_helper.rb
119
- - spec/support/matchers/give_the_outcome.rb
120
- homepage: http://github.com/nigel-lowry/random_outcome
107
+ homepage: https://github.com/nigel-lowry/random_outcome
121
108
  licenses:
122
109
  - MIT
123
110
  metadata: {}
@@ -127,18 +114,18 @@ require_paths:
127
114
  - lib
128
115
  required_ruby_version: !ruby/object:Gem::Requirement
129
116
  requirements:
130
- - - '>='
117
+ - - ">="
131
118
  - !ruby/object:Gem::Version
132
119
  version: '0'
133
120
  required_rubygems_version: !ruby/object:Gem::Requirement
134
121
  requirements:
135
- - - '>='
122
+ - - ">="
136
123
  - !ruby/object:Gem::Version
137
124
  version: '0'
138
125
  requirements: []
139
126
  rubyforge_project:
140
- rubygems_version: 2.1.5
127
+ rubygems_version: 2.6.6
141
128
  signing_key:
142
129
  specification_version: 4
143
- summary: Small Ruby gem for generating outcomes with specified probabilities
130
+ summary: Small gem for generating random outcomes.
144
131
  test_files: []
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
data/.rvmrc DELETED
@@ -1,62 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
- # development environment upon cd'ing into the directory
5
-
6
- # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
- # Only full ruby name is supported here, for short names use:
8
- # echo "rvm use 2.0.0" > .rvmrc
9
- environment_id="ruby-2.0.0-p247@random_outcome"
10
-
11
- # Uncomment the following lines if you want to verify rvm version per project
12
- # rvmrc_rvm_version="1.22.14 (stable)" # 1.10.1 seems like a safe start
13
- # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | __rvm_awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
- # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
- # return 1
16
- # }
17
-
18
- # First we attempt to load the desired environment directly from the environment
19
- # file. This is very fast and efficient compared to running through the entire
20
- # CLI and selector. If you want feedback on which environment was used then
21
- # insert the word 'use' after --create as this triggers verbose mode.
22
- if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
- && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
- then
25
- \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
- for __hook in "${rvm_path:-$HOME/.rvm}/hooks/after_use"*
27
- do
28
- if [[ -f "${__hook}" && -x "${__hook}" && -s "${__hook}" ]]
29
- then \. "${__hook}" || true
30
- fi
31
- done
32
- unset __hook
33
- if (( ${rvm_use_flag:=1} >= 2 )) # display only when forced
34
- then
35
- if [[ $- == *i* ]] # check for interactive shells
36
- then printf "%b" "Using: $(tput setaf 2 2>/dev/null)$GEM_HOME$(tput sgr0 2>/dev/null)
37
- " # show the user the ruby and gemset they are using in green
38
- else printf "%b" "Using: $GEM_HOME
39
- " # don't use colors in non-interactive shells
40
- fi
41
- fi
42
- else
43
- # If the environment file has not yet been created, use the RVM CLI to select.
44
- rvm --create "$environment_id" || {
45
- echo "Failed to create RVM environment '${environment_id}'."
46
- return 1
47
- }
48
- fi
49
-
50
- # If you use bundler, this might be useful to you:
51
- # if [[ -s Gemfile ]] && {
52
- # ! builtin command -v bundle >/dev/null ||
53
- # builtin command -v bundle | GREP_OPTIONS="" \grep $rvm_path/bin/bundle >/dev/null
54
- # }
55
- # then
56
- # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
57
- # gem install bundler
58
- # fi
59
- # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
60
- # then
61
- # bundle install | GREP_OPTIONS="" \grep -vE '^Using|Your bundle is complete'
62
- # fi
data/README.rdoc DELETED
@@ -1,19 +0,0 @@
1
- = random_outcome
2
-
3
- Description goes here.
4
-
5
- == Contributing to random_outcome
6
-
7
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
- * Fork the project.
10
- * Start a feature/bugfix branch.
11
- * Commit and push until you are happy with your contribution.
12
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
-
15
- == Copyright
16
-
17
- Copyright (c) 2013 Nigel Lowry. See LICENSE.txt for
18
- further details.
19
-
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.0
data/lib/simulator.rb DELETED
@@ -1,61 +0,0 @@
1
- require 'active_support/all'
2
-
3
- # Generates outcomes with specified probabilities
4
- class Simulator
5
-
6
- # creates a new Simulator which will return the desired outcomes with the given probability
7
- # @param outcome_to_probability [Hash<Symbol, Number>] hash of outcomes to their probability (represented as
8
- # numbers between zero and one)
9
- # @note raises errors if there is only one possible outcome (why bother using this if there's only one
10
- # outcome?), if the probabilities don't total one (use Rationals if this proves problematic with rounding) or
11
- # if any of the outcomes are impossible (why include them if they can never happen?)
12
- def initialize outcome_to_probability
13
- raise_if_only_have_one_outcome outcome_to_probability
14
- raise_if_probabilities_total_isnt_one outcome_to_probability
15
- raise_if_have_any_impossible_outcomes outcome_to_probability
16
- raise_if_have_any_negative_probabilities outcome_to_probability
17
- @probability_range_to_outcome = probability_range_to_outcome outcome_to_probability
18
- end
19
-
20
- # generate an outcome with the initialised probabilities
21
- # @return [Symbol] symbol for outcome
22
- def outcome
23
- num = random_float_including_zero_and_excluding_one # don't inline
24
- @probability_range_to_outcome.detect {|probability_range, _| num.in? probability_range }.last
25
- end
26
-
27
- private
28
-
29
- def raise_if_only_have_one_outcome outcome_to_probability
30
- raise "only have one outcome" unless outcome_to_probability.many?
31
- end
32
-
33
- def raise_if_probabilities_total_isnt_one outcome_to_probability
34
- raise "probabilities don't total one" unless outcome_to_probability.values.sum == 1.0
35
- end
36
-
37
- def raise_if_have_any_impossible_outcomes outcome_to_probability
38
- raise "have an impossible outcome" if outcome_to_probability.has_value? 0.0
39
- end
40
-
41
- def raise_if_have_any_negative_probabilities outcome_to_probability
42
- raise "have negative probability" if outcome_to_probability.values.any? {|probability| probability < 0.0 }
43
- end
44
-
45
- def random_float_including_zero_and_excluding_one
46
- rand
47
- end
48
-
49
- def probability_range_to_outcome outcome_to_probability
50
- range_to_outcome = {}
51
- lower_bound = 0.0
52
-
53
- outcome_to_probability.each do |outcome, probability|
54
- upper_bound = lower_bound + probability
55
- range_to_outcome.store lower_bound...upper_bound, outcome
56
- lower_bound = upper_bound
57
- end
58
-
59
- range_to_outcome
60
- end
61
- end
@@ -1,81 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe Simulator do
4
-
5
- context "p(A) = 10%, p(B) = 90%" do
6
- before :all do
7
- @simulator = Simulator.new(A: 0.1, B: 0.9)
8
- end
9
-
10
- subject { @simulator }
11
-
12
- it { should give_the_outcome(:A).with_the_probability(0.1) }
13
- it { should give_the_outcome(:B).with_the_probability(0.9) }
14
- it { should give_the_outcome(:C).with_the_probability(0.0) }
15
- end
16
-
17
- context "p(A) = 40%, p(B) = 60%" do
18
- before :all do
19
- @simulator = Simulator.new(A: 0.4, B: 0.6)
20
- end
21
-
22
- subject { @simulator }
23
-
24
- it { should give_the_outcome(:A).with_the_probability(0.4) }
25
- it { should give_the_outcome(:B).with_the_probability(0.6) }
26
- end
27
-
28
- context "p(A) = 10%, p(B) = 20%, p(C) = 70%" do
29
- before :all do
30
- @simulator = Simulator.new(A: 0.1, B: 0.2, C: 0.7)
31
- end
32
-
33
- subject { @simulator }
34
-
35
- it { should give_the_outcome(:A).with_the_probability(0.1) }
36
- it { should give_the_outcome(:B).with_the_probability(0.2) }
37
- it { should give_the_outcome(:C).with_the_probability(0.7) }
38
- end
39
-
40
- context "with no outcomes" do
41
- it "will raise error" do
42
- expect { Simulator.new({}) }.to raise_error
43
- end
44
- end
45
-
46
- context "with only one outcome" do
47
- it "will raise error" do
48
- expect { Simulator.new(A: 1.0) }.to raise_error
49
- end
50
- end
51
-
52
- context "with any probabilities less than 0.0" do
53
- it "will raise error" do
54
- expect { Simulator.new(A: 0.9, B: 0.2, C: -0.1) }.to raise_error
55
- end
56
- end
57
-
58
- context "with any probabilities greater than or equal to 1.0" do
59
- it "will raise error" do
60
- expect { Simulator.new(A: 1.1, B: 0.1, C: -0.2) }.to raise_error
61
- end
62
- end
63
-
64
- context "with probabilities summing to less than 1.0" do
65
- it "will raise error" do
66
- expect { Simulator.new(A: 0.1, B: 0.89) }.to raise_error
67
- end
68
- end
69
-
70
- context "with probabilities summing to more than 1.0" do
71
- it "will raise error" do
72
- expect { Simulator.new(A: 0.1, B: 0.91) }.to raise_error
73
- end
74
- end
75
-
76
- context "with an impossible event" do
77
- it "will raise error" do
78
- expect { Simulator.new(A: 0.1, B: 0.9, C: 0.0) }.to raise_error
79
- end
80
- end
81
- end
data/spec/spec_helper.rb DELETED
@@ -1,12 +0,0 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- $LOAD_PATH.unshift(File.dirname(__FILE__))
3
- require 'rspec'
4
- require 'simulator'
5
-
6
- # Requires supporting files with custom matchers and macros, etc,
7
- # in ./support/ and its subdirectories.
8
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
-
10
- RSpec.configure do |config|
11
-
12
- end
@@ -1,28 +0,0 @@
1
- RSpec::Matchers.define :give_the_outcome do |outcome|
2
- match do |actual|
3
- outcome_count = 0
4
- trial_count = 100_000
5
-
6
- trial_count.times do
7
- outcome_count += 1 if actual.outcome == outcome
8
- end
9
-
10
- (outcome_count / trial_count.to_f).should be_within(0.01).of(@probability)
11
- end
12
-
13
- chain :with_the_probability do |probability|
14
- @probability = probability
15
- end
16
-
17
- failure_message_for_should do |actual|
18
- "expected that #{outcome} would occur with a probability of #{@probability}"
19
- end
20
-
21
- failure_message_for_should_not do |actual|
22
- "expected that #{outcome} would not occur with a probability of #{@probability}"
23
- end
24
-
25
- description do
26
- "occur with a probability of #{@probability}"
27
- end
28
- end