normal_random 1.0.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: 00ea628ca5c6f3c8a9d2e12a222c7470945f100f
4
+ data.tar.gz: 69e204f89522f23538b57db274fba538d9cdc488
5
+ SHA512:
6
+ metadata.gz: e762e7e8e77750e279b48d69c3e9fb5db6fc058c5da7db830d814f3e9b121cfb05fd9af32c0b4db0b0eaae5755cfee1df2ff69546b109553091ef37f599d5c95
7
+ data.tar.gz: 96339633231f0c83beb452473783ea4109e9d8fe0964e6a5c21eef794b3ed2764cfdf69489b4b66499d0146d4929bfa74d25f2e70de91dce6b6d6afc22e2758f
data/.gitignore ADDED
@@ -0,0 +1,46 @@
1
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
2
+
3
+ *.iml
4
+
5
+ ## Directory-based project format:
6
+ .idea/
7
+ # if you remove the above rule, at least ignore the following:
8
+
9
+ # User-specific stuff:
10
+ # .idea/workspace.xml
11
+ # .idea/tasks.xml
12
+ # .idea/dictionaries
13
+
14
+ # Sensitive or high-churn files:
15
+ # .idea/dataSources.ids
16
+ # .idea/dataSources.xml
17
+ # .idea/sqlDataSources.xml
18
+ # .idea/dynamic.xml
19
+ # .idea/uiDesigner.xml
20
+
21
+ # Gradle:
22
+ # .idea/gradle.xml
23
+ # .idea/libraries
24
+
25
+ # Mongo Explorer plugin:
26
+ # .idea/mongoSettings.xml
27
+
28
+ ## File-based project format:
29
+ *.ipr
30
+ *.iws
31
+
32
+ ## Plugin-specific files:
33
+
34
+ # IntelliJ
35
+ /out/
36
+
37
+ # mpeltonen/sbt-idea plugin
38
+ .idea_modules/
39
+
40
+ # JIRA plugin
41
+ atlassian-ide-plugin.xml
42
+
43
+ # Crashlytics plugin (for Android Studio and IntelliJ)
44
+ com_crashlytics_export_strings.xml
45
+ crashlytics.properties
46
+ crashlytics-build.properties
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,89 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ normal_random (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ actionpack (4.2.3)
10
+ actionview (= 4.2.3)
11
+ activesupport (= 4.2.3)
12
+ rack (~> 1.6)
13
+ rack-test (~> 0.6.2)
14
+ rails-dom-testing (~> 1.0, >= 1.0.5)
15
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
16
+ actionview (4.2.3)
17
+ activesupport (= 4.2.3)
18
+ builder (~> 3.1)
19
+ erubis (~> 2.7.0)
20
+ rails-dom-testing (~> 1.0, >= 1.0.5)
21
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
22
+ activesupport (4.2.3)
23
+ i18n (~> 0.7)
24
+ json (~> 1.7, >= 1.7.7)
25
+ minitest (~> 5.1)
26
+ thread_safe (~> 0.3, >= 0.3.4)
27
+ tzinfo (~> 1.1)
28
+ builder (3.2.2)
29
+ diff-lcs (1.2.5)
30
+ erubis (2.7.0)
31
+ i18n (0.7.0)
32
+ json (1.8.3)
33
+ loofah (2.0.2)
34
+ nokogiri (>= 1.5.9)
35
+ mini_portile (0.6.2)
36
+ minitest (5.7.0)
37
+ minitest-rails (2.2.0)
38
+ minitest (~> 5.7)
39
+ railties (~> 4.1)
40
+ nokogiri (1.6.6.2)
41
+ mini_portile (~> 0.6.0)
42
+ rack (1.6.4)
43
+ rack-test (0.6.3)
44
+ rack (>= 1.0)
45
+ rails-deprecated_sanitizer (1.0.3)
46
+ activesupport (>= 4.2.0.alpha)
47
+ rails-dom-testing (1.0.6)
48
+ activesupport (>= 4.2.0.beta, < 5.0)
49
+ nokogiri (~> 1.6.0)
50
+ rails-deprecated_sanitizer (>= 1.0.1)
51
+ rails-html-sanitizer (1.0.2)
52
+ loofah (~> 2.0)
53
+ railties (4.2.3)
54
+ actionpack (= 4.2.3)
55
+ activesupport (= 4.2.3)
56
+ rake (>= 0.8.7)
57
+ thor (>= 0.18.1, < 2.0)
58
+ rake (10.4.2)
59
+ rspec (3.3.0)
60
+ rspec-core (~> 3.3.0)
61
+ rspec-expectations (~> 3.3.0)
62
+ rspec-mocks (~> 3.3.0)
63
+ rspec-core (3.3.2)
64
+ rspec-support (~> 3.3.0)
65
+ rspec-expectations (3.3.1)
66
+ diff-lcs (>= 1.2.0, < 2.0)
67
+ rspec-support (~> 3.3.0)
68
+ rspec-mocks (3.3.2)
69
+ diff-lcs (>= 1.2.0, < 2.0)
70
+ rspec-support (~> 3.3.0)
71
+ rspec-support (3.3.0)
72
+ thor (0.19.1)
73
+ thread_safe (0.3.5)
74
+ tzinfo (1.2.2)
75
+ thread_safe (~> 0.1)
76
+ yard (0.8.7.6)
77
+
78
+ PLATFORMS
79
+ ruby
80
+
81
+ DEPENDENCIES
82
+ minitest-rails (~> 2.2)
83
+ normal_random!
84
+ rake (~> 10.4)
85
+ rspec (~> 3.3)
86
+ yard
87
+
88
+ BUNDLED WITH
89
+ 1.10.1
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake'
3
+ require 'rspec/core/rake_task'
4
+
5
+ namespace :spec do
6
+
7
+ RSpec::Core::RakeTask.new(:normal) do |t|
8
+ t.pattern ='spec/**/*_spec.rb'
9
+ t.rcov = false
10
+ end
11
+
12
+ end
13
+
14
+ desc "RSpec tests"
15
+ task "spec" => "spec:normal"
16
+
17
+ task "default" => "spec"
data/Readme.md ADDED
@@ -0,0 +1,45 @@
1
+ # Normal Random
2
+
3
+ Normal Random is a ruby gem that generates random numbers along a
4
+ normally distributed curve.
5
+
6
+ ## Usage
7
+
8
+ The `RandomNumber` class works like the standard ruby `Random` class.
9
+
10
+ ```ruby
11
+ RandomNumber.new.rand #=> 114.67815448792281
12
+
13
+ # or
14
+
15
+ random_number_generator = RandomNumber.new
16
+ random_number_generator.rand #=> 109.96615852194628
17
+ random_number_generator.rand #=> 91.78189126576613
18
+ ```
19
+
20
+ ## Advanced Usage
21
+
22
+ By default `NormalRandom` has a **mu (mean) of 100** and a
23
+ **sigma (standard deviation) of 15**. You can specify either
24
+ of these by passing the appropriate variables to the `rand`
25
+ method.
26
+
27
+ ```ruby
28
+ random_number_generator = RandomNumber.new
29
+
30
+ random_number_generator.rand(mu: 0, sigma: 1) #=> 0.4813873347443289
31
+ ```
32
+
33
+ # Contributors
34
+
35
+ `normal_random` is solely Pete Michaud's (me@petermichaud.com) fault, so blame him for everything.
36
+
37
+ # License
38
+
39
+ (The MIT License)
40
+
41
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
42
+
43
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
44
+
45
+ THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,23 @@
1
+ require 'normal_random/version'
2
+
3
+ class NormalRandom
4
+
5
+ DEFAULT_MU = 100
6
+ DEFAULT_SIGMA = 15
7
+
8
+ attr_accessor :rng
9
+
10
+ def initialize
11
+ self.rng = Random.new
12
+ end
13
+
14
+ def rand(mu: DEFAULT_MU, sigma: DEFAULT_SIGMA)
15
+ (standard_deviations * sigma) + mu
16
+ end
17
+
18
+ def box_muller
19
+ Math.sqrt(-2*Math.log(rng.rand))*Math.cos(2*Math::PI*rng.rand)
20
+ end
21
+ alias_method :standard_deviations, :box_muller
22
+
23
+ end
@@ -0,0 +1,3 @@
1
+ class NormalRandom
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "normal_random/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "normal_random"
7
+ s.version = NormalRandom::VERSION
8
+ s.authors = ["Pete Michaud"]
9
+ s.email = ["me@petermichaud.com"]
10
+ s.homepage = "http://github.com/PeteMichaud/normal_random"
11
+ s.summary = "Generates Normally Distributed, Random Numbers"
12
+ s.description = "Generates Normally Distributed, Random Numbers"
13
+ s.rubyforge_project = "normal_random"
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.licenses = ['MIT']
17
+ s.add_development_dependency 'rake', '~> 10.4'
18
+ s.add_development_dependency 'rspec', '~> 3.3'
19
+ s.add_development_dependency 'minitest-rails', '~> 2.2'
20
+ s.add_development_dependency 'minitest', '~> 5.7' if RUBY_PLATFORM == "java"
21
+ end
Binary file
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'NormalRandom.rand' do
4
+
5
+ it "should work without arguments" do
6
+ NormalRandom.new.rand.should
7
+ be_within(NormalRandom::DEFAULT_SIGMA*6).
8
+ of(NormalRandom::DEFAULT_MU)
9
+ end
10
+
11
+ it "should work with mu" do
12
+ mu = 50
13
+ NormalRandom.new.rand(mu: mu).should
14
+ be_within(NormalRandom::DEFAULT_SIGMA*6).
15
+ of(mu)
16
+ end
17
+
18
+ it "should work with mu and sigma" do
19
+ mu = 0
20
+ sigma = 1
21
+ NormalRandom.new.rand(mu: mu, sigma: sigma).should
22
+ be_within(sigma*6).
23
+ of(mu)
24
+ end
25
+
26
+ it "should work with sigma" do
27
+ sigma = 1
28
+ NormalRandom.new.rand(sigma: sigma).should
29
+ be_within(sigma*6).
30
+ of(NormalRandom::DEFAULT_MU)
31
+ end
32
+
33
+ end
@@ -0,0 +1 @@
1
+ require 'normal_random'
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: normal_random
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Pete Michaud
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '10.4'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '10.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.2'
55
+ description: Generates Normally Distributed, Random Numbers
56
+ email:
57
+ - me@petermichaud.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".idea/.name"
64
+ - ".idea/.rakeTasks"
65
+ - ".idea/misc.xml"
66
+ - ".idea/modules.xml"
67
+ - ".idea/normal_random.iml"
68
+ - ".idea/vcs.xml"
69
+ - ".idea/workspace.xml"
70
+ - Gemfile
71
+ - Gemfile.lock
72
+ - Rakefile
73
+ - Readme.md
74
+ - lib/normal_random.rb
75
+ - lib/normal_random/version.rb
76
+ - normal_random.gemspec
77
+ - pkg/normal_random-1.0.0.gem
78
+ - spec/normal_random/rand_spec.rb
79
+ - spec/spec_helper.rb
80
+ homepage: http://github.com/PeteMichaud/normal_random
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project: normal_random
100
+ rubygems_version: 2.4.5
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: Generates Normally Distributed, Random Numbers
104
+ test_files:
105
+ - spec/normal_random/rand_spec.rb
106
+ - spec/spec_helper.rb
107
+ has_rdoc: