random_logic 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b6e35d080d6f7d64dd0632e259b8ef73a36f8c20
4
+ data.tar.gz: 9f9bf343e3f4079ce8a1d1134c941fb165d69904
5
+ SHA512:
6
+ metadata.gz: fce294fcf3c121a6d5ee27dbeca01e22da94a6737bc51ea34e6b8ec96e77dde74663c8aa1def6b06f595c072d1b2e94f8c92d15265e95681f2c0df8d94812cf2
7
+ data.tar.gz: 67e57a30270aae3ea63d14c20325a3fee7cc3b80dd12297dd4c77c745e384f7c8e1b609f6cdc55dc5a1502c6aa9fb5a19492de9a8ecee4ce76353923014e6490
@@ -0,0 +1,10 @@
1
+ *.gem
2
+ .bundle
3
+ .idea
4
+ Gemfile.lock
5
+ gemfiles/*.lock
6
+ coverage/*
7
+ pkg/*
8
+
9
+ doc
10
+ log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in random_logic.gemspec
4
+ gemspec
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2016 Akira Narita
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:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
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.
@@ -0,0 +1,103 @@
1
+ # RandomLogic
2
+
3
+ A random logic module provide various randomise calculation.
4
+ The japanese article written by ICS [JavaScript開発に役立つ重要なランダムの数式まとめ](https://ics.media/entry/11292) inspired me to write RandomLogic gem.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'random_logic'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install random_logic
21
+
22
+ ## Fearures
23
+
24
+ Easy to use random logic.
25
+
26
+ ## Usage
27
+
28
+ **Inverse value**
29
+
30
+ ```ruby
31
+ RandomLogic.inverse(rand)
32
+ ```
33
+
34
+
35
+ **Random number of addition**
36
+ Bias the value in the center
37
+
38
+ ```ruby
39
+ RandomLogic.add
40
+ ```
41
+
42
+ **Random number of multiplication**
43
+ Bias the value near 0
44
+
45
+ ```ruby
46
+ RandomLogic.multiply
47
+ ```
48
+
49
+ **Inversion of random number of multiplication**
50
+ Bias the value near 1
51
+ ```ruby
52
+ RandomLogic.multiply_inverse
53
+ ```
54
+
55
+ **The square of the random number**
56
+ Further increasing the proportion of the value near 0
57
+
58
+ ```ruby
59
+ RandomLogic.square
60
+ ```
61
+
62
+ **Inversion of the square of the random number**
63
+ Further increasing the proportion of the value near 1
64
+
65
+ ```ruby
66
+ RandomLogic.square_inverse
67
+ ```
68
+
69
+ **Random number of square root**
70
+ Increase linearly frequency of occurrence from 0.0 to 1.0.
71
+
72
+ ```ruby
73
+ RandomLogic.sqrt
74
+ ```
75
+
76
+ **Inversion of random number of square root**
77
+ Increase linearly frequency of occurrence from 1.0 to 0.0.
78
+
79
+ ```ruby
80
+ RandomLogic.sqrt_inverse
81
+ ```
82
+
83
+ **Normal random number**
84
+
85
+ ```ruby
86
+ RandomLogic.normal
87
+ ```
88
+
89
+ **Normal random with re-try logic when the random value was lower than 0 or higher than 1**
90
+
91
+ ```ruby
92
+ RandomLogic.normal_rand
93
+ ```
94
+
95
+ ## Development
96
+
97
+ 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.
98
+
99
+ 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).
100
+
101
+ ## Contributing
102
+
103
+ Bug reports and pull requests are welcome on GitHub at https://github.com/akinrt/random_logic.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "random_logic"
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
@@ -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,70 @@
1
+ require "random_logic/version"
2
+
3
+ module RandomLogic
4
+
5
+ def self.name
6
+ "RandomLogin"
7
+ end
8
+ # Inverse value
9
+ def self.inverse(value)
10
+ 1.0 - value
11
+ end
12
+
13
+ # Random number of addition
14
+ # Bias the value in the center
15
+ def self.add
16
+ rand + rand / 2
17
+ end
18
+
19
+ # Random number of multiplication
20
+ # Bias the value near 0
21
+ def self.multiply
22
+ rand * rand
23
+ end
24
+
25
+ # Inversion of random number of multiplication
26
+ # Bias the value near 1
27
+ def self.multiply_inverse
28
+ inverse(rand * rand)
29
+ end
30
+
31
+ # The square of the random number
32
+ # Further increasing the proportion of the value near 0
33
+ def self.square
34
+ r = rand * rand
35
+ r * r
36
+ end
37
+
38
+ # Inversion of the square of the random number
39
+ # Further increasing the proportion of the value near 1
40
+ def self.square_inverse
41
+ inverse(square)
42
+ end
43
+
44
+ # Random number of square root
45
+ # Increase linearly frequency of occurrence from 0.0 to 1.0.
46
+ def self.sqrt
47
+ Math.sqrt rand
48
+ end
49
+
50
+ # Inversion of random number of square root
51
+ # Increase linearly frequency of occurrence from 1.0 to 0.0.
52
+ def self.sqrt_inverse
53
+ inverse(sqrt)
54
+ end
55
+
56
+ # Normal random number
57
+ def self.normal
58
+ value = Math.sqrt(-2.0 * Math.log(rand)) * Math.sin(2.0 * Math::PI * rand)
59
+ (value + 3) / 6
60
+ end
61
+
62
+ # Normal random with re-try logic when the random value was lower than 0 or higher than 1
63
+ def self.normal_rand
64
+ while (true) do
65
+ value = normal
66
+ return value if (0 <= value && value < 1)
67
+ end
68
+ end
69
+
70
+ end
@@ -0,0 +1,3 @@
1
+ module RandomLogic
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'random_logic/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "random_logic"
8
+ spec.version = RandomLogic::VERSION
9
+ spec.authors = ["akinrt"]
10
+ spec.email = ["aki.d.sc@gmail.com"]
11
+
12
+ spec.summary = %q{A random logic module provide various randomise calculation.}
13
+ spec.description = %q{A random logic module provide various randomise calculation.
14
+ The japanese article written by ICS [JavaScript開発に役立つ重要なランダムの数式まとめ](https://ics.media/entry/11292) inspired me to write RandomLogic gem.}
15
+ spec.homepage = "https://github.com/akinrt/random_logic"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.11"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: random_logic
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - akinrt
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-07 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: |-
56
+ A random logic module provide various randomise calculation.
57
+ The japanese article written by ICS [JavaScript開発に役立つ重要なランダムの数式まとめ](https://ics.media/entry/11292) inspired me to write RandomLogic gem.
58
+ email:
59
+ - aki.d.sc@gmail.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - ".rspec"
66
+ - ".travis.yml"
67
+ - Gemfile
68
+ - MIT-LICENSE
69
+ - README.md
70
+ - Rakefile
71
+ - bin/console
72
+ - bin/setup
73
+ - lib/random_logic.rb
74
+ - lib/random_logic/version.rb
75
+ - random_logic.gemspec
76
+ homepage: https://github.com/akinrt/random_logic
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.6.1
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: A random logic module provide various randomise calculation.
100
+ test_files: []
101
+ has_rdoc: