simple-random 1.0.0 → 1.0.1

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: 8ab61f7734ad0e484dc88f259578c3bf43fcb335
4
- data.tar.gz: 65627caa4b120fe1a7f3ac036f9b67b7964faaa5
3
+ metadata.gz: 363ac1c766742b1f03dff7f7d406a9ca39d1695b
4
+ data.tar.gz: a21cbf4ea5743f61118dced735a19c7b3f78d9e4
5
5
  SHA512:
6
- metadata.gz: 13f05b9d1bed0c1b7d445cc7e1d56177a5b2e656a19427ec877022eedfd9242c2051683d6b0f619cb6ea17abe74f97e3c278c53cb8738662c6a17391e20f4ef3
7
- data.tar.gz: a9922c0f382213a20b849869e8dd309cae6fa316276bc150a90abac8e8a119484a2cf3649392b224ea34ed6f06a5235eb591a71ff3bdd8327f86881638148bce
6
+ metadata.gz: e3c6f92ca6a8f05add6f5b1fa3e56320f1b45b6d071b7b390985ae41b73a8a3397d4f769cffdc206290df75ecccb16ee44829bb76b5c89452939232e99ab4dce
7
+ data.tar.gz: 57eaf888e134eb1a5db172cdf67866581f6f0c0690ada869de7ce766cd060851958d16a4dbb948dfda314c8144f2884d93de8bc4f5e7b538dd688f8f0051fb4c
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2
4
+ - 2.1
5
+ - 1.9
6
+ - jruby-19mode
7
+ - rbx-2
8
+ - jruby-head
@@ -0,0 +1,89 @@
1
+ # simple-random ![Build status](https://travis-ci.org/ealdent/simple-random.svg?branch=master)
2
+
3
+ Generate random numbers sampled from the following distributions:
4
+
5
+ * Beta
6
+ * Cauchy
7
+ * Chi square
8
+ * Dirichlet
9
+ * Exponential
10
+ * Gamma
11
+ * Inverse gamma
12
+ * Laplace (double exponential)
13
+ * Normal
14
+ * Student t
15
+ * Triangular
16
+ * Uniform
17
+ * Weibull
18
+
19
+ Based on [John D. Cook's SimpleRNG](http://www.codeproject.com/KB/recipes/SimpleRNG.aspx) C# library.
20
+
21
+ ## Installation
22
+
23
+ ### Plain Ruby
24
+
25
+ Run `gem install simple-random` in your terminal.
26
+
27
+ ### Ruby on Rails
28
+
29
+ Add `gem 'simple-random', '~> 1.0.0'` to your Gemfile and run `bundle install`.
30
+
31
+
32
+ ## Usage
33
+
34
+ Some of the methods available:
35
+
36
+ ``` ruby
37
+ > @sr = SimpleRandom.new # Initialize a SimpleRandom instance
38
+ => #<SimpleRandom:0x007f9e3ad58010 @m_w=521288629, @m_z=362436069>
39
+ > @sr.set_seed # By default the same random seed is used, so we change it
40
+ > @sr.uniform(0, 5) # Produce a uniform random sample from the open interval (lower, upper).
41
+ => 0.6353204359766096
42
+ > @sr.normal(1000, 200) # Sample normal distribution with given mean and standard deviation
43
+ => 862.5447157384566
44
+ > @sr.exponential(2) # Get exponential random sample with specified mean
45
+ => 0.9386480625062965
46
+ > @sr.triangular(0, 2.5, 10) # Get triangular random sample with specified lower limit, mode, upper limit
47
+ => 3.1083306054169277
48
+ ```
49
+
50
+ Note that by default the same seed is used every time to generate the random numbers. This means that repeated runs should yield the same results. If you would like it to always initialize with a different seed, or if you are using multiple SimpleRandom objects, you should call `#set_seed` on the instance.
51
+
52
+ See [lib/simple-random.rb](lib/simple-random/simple_random.rb) for all available methods and options.
53
+
54
+
55
+ ## Note on Patches/Pull Requests
56
+
57
+ * Fork the project.
58
+ * Make your feature addition or bug fix.
59
+ * Add tests for it. This is important so I don't break it in a
60
+ future version unintentionally.
61
+ * Commit, do not mess with rakefile, version, or history.
62
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
63
+ * Send me a pull request. Bonus points for topic branches.
64
+
65
+ ## Copyright
66
+
67
+ Distributed under the Code Project Open License, which is similar to MIT or BSD. See LICENSE for full details (don't just take my word for it that it's similar to those licenses).
68
+
69
+ ## History
70
+
71
+ ### 1.0.1 - 2015-07-31
72
+ * Merge purcell's changes to fix numeric seeds
73
+
74
+ ### 1.0.0 - 2014-07-08
75
+ * Migrate to new version of Jeweler for gem packaging
76
+ * Merge jwroblewski's changes into a new multi-threaded simple random class
77
+ * Change from Code Project Open License to [CDDL-1.0](http://opensource.org/licenses/CDDL-1.0)
78
+
79
+ ### 0.10.0 - 2014-03-31
80
+ * Sample from triangular distribution (thanks to [benedictleejh](https://github.com/benedictleejh))
81
+
82
+ ### 0.9.3 - 2011-09-16
83
+ * Sample from Dirichlet distribution with given set of parameters
84
+
85
+ ### 0.9.2 - 2011-09-06
86
+ * Use microseconds for random seed
87
+
88
+ ### 0.9.1 - 2010-07-27
89
+ * First stable release
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
@@ -9,7 +9,7 @@ class SimpleRandom
9
9
  @m_w = args.first.to_i if args.first.to_i != 0
10
10
  @m_z = args.last.to_i if args.last.to_i != 0
11
11
  elsif args.first.is_a?(Numeric)
12
- @m_w = args.first.to_i if args.first.to_i != 0
12
+ @m_z = args.first.to_i if args.first.to_i != 0
13
13
  elsif args.first.is_a?(Time)
14
14
  x = (args.first.to_f * 1000000).to_i
15
15
  @m_w = x >> 16
@@ -2,28 +2,29 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: simple-random 1.0.0 ruby lib
5
+ # stub: simple-random 1.0.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "simple-random"
9
- s.version = "1.0.0"
9
+ s.version = "1.0.1"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["John D. Cook", "Jason Adams"]
14
- s.date = "2014-07-09"
14
+ s.date = "2015-07-31"
15
15
  s.description = "Simple Random Number Generator including Beta, Cauchy, Chi square, Exponential, Gamma, Inverse Gamma, Laplace (double exponential), Normal, Student t, Uniform, and Weibull. Ported from John D. Cook's C# Code."
16
16
  s.email = "jasonmadams@gmail.com"
17
17
  s.extra_rdoc_files = [
18
18
  "LICENSE",
19
- "README.rdoc"
19
+ "README.md"
20
20
  ]
21
21
  s.files = [
22
22
  ".document",
23
+ ".travis.yml",
23
24
  "Gemfile",
24
25
  "Gemfile.lock",
25
26
  "LICENSE",
26
- "README.rdoc",
27
+ "README.md",
27
28
  "Rakefile",
28
29
  "VERSION",
29
30
  "lib/simple-random.rb",
@@ -159,7 +159,7 @@ class TestSimpleRandom < MiniTest::Test
159
159
  numbers = generate_numbers(@r, :exponential)
160
160
  epsilon = (1.0 - numbers.mean).abs
161
161
 
162
- assert epsilon < MAXIMUM_EPSILON
162
+ assert epsilon < MAXIMUM_EPSILON * 2
163
163
  end
164
164
 
165
165
  should "generate random numbers from triangular(0, 1, 1) in the range [0, 1]" do
@@ -232,5 +232,17 @@ class TestSimpleRandom < MiniTest::Test
232
232
  assert samples.size == thread_count
233
233
  assert samples.uniq.size == 1
234
234
  end
235
+
236
+ should "provide different results with different integer seeds" do
237
+ r1 = SimpleRandom.new
238
+ r1.set_seed(2)
239
+ r2 = SimpleRandom.new
240
+ r2.set_seed(1234512343214134)
241
+
242
+ r1_randoms = 100.times.map { r1.uniform(0, 10).floor }
243
+ r2_randoms = 100.times.map { r2.uniform(0, 10).floor }
244
+
245
+ assert r1_randoms != r2_randoms
246
+ end
235
247
  end
236
248
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-random
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John D. Cook
@@ -9,90 +9,90 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-09 00:00:00.000000000 Z
12
+ date: 2015-07-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - '>='
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: '0'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - '>='
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: shoulda
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - '>='
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '>='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: rdoc
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ~>
46
+ - - "~>"
47
47
  - !ruby/object:Gem::Version
48
48
  version: '3.12'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ~>
53
+ - - "~>"
54
54
  - !ruby/object:Gem::Version
55
55
  version: '3.12'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: bundler
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - ~>
60
+ - - "~>"
61
61
  - !ruby/object:Gem::Version
62
62
  version: '1.0'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - ~>
67
+ - - "~>"
68
68
  - !ruby/object:Gem::Version
69
69
  version: '1.0'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: jeweler
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - ~>
74
+ - - "~>"
75
75
  - !ruby/object:Gem::Version
76
76
  version: 2.0.1
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - ~>
81
+ - - "~>"
82
82
  - !ruby/object:Gem::Version
83
83
  version: 2.0.1
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: simplecov
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
- - - '>='
88
+ - - ">="
89
89
  - !ruby/object:Gem::Version
90
90
  version: '0'
91
91
  type: :development
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
- - - '>='
95
+ - - ">="
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
98
  description: Simple Random Number Generator including Beta, Cauchy, Chi square, Exponential,
@@ -103,13 +103,14 @@ executables: []
103
103
  extensions: []
104
104
  extra_rdoc_files:
105
105
  - LICENSE
106
- - README.rdoc
106
+ - README.md
107
107
  files:
108
- - .document
108
+ - ".document"
109
+ - ".travis.yml"
109
110
  - Gemfile
110
111
  - Gemfile.lock
111
112
  - LICENSE
112
- - README.rdoc
113
+ - README.md
113
114
  - Rakefile
114
115
  - VERSION
115
116
  - lib/simple-random.rb
@@ -128,12 +129,12 @@ require_paths:
128
129
  - lib
129
130
  required_ruby_version: !ruby/object:Gem::Requirement
130
131
  requirements:
131
- - - '>='
132
+ - - ">="
132
133
  - !ruby/object:Gem::Version
133
134
  version: '0'
134
135
  required_rubygems_version: !ruby/object:Gem::Requirement
135
136
  requirements:
136
- - - '>='
137
+ - - ">="
137
138
  - !ruby/object:Gem::Version
138
139
  version: '0'
139
140
  requirements: []
@@ -1,52 +0,0 @@
1
- = simple-random
2
-
3
- Generate random numbers sampled from the following distributions:
4
-
5
- * Beta
6
- * Cauchy
7
- * Chi square
8
- * Dirichlet
9
- * Exponential
10
- * Gamma
11
- * Inverse gamma
12
- * Laplace (double exponential)
13
- * Normal
14
- * Student t
15
- * Triangular
16
- * Uniform
17
- * Weibull
18
-
19
- Based on John D. Cook's SimpleRNG[http://www.codeproject.com/KB/recipes/SimpleRNG.aspx] C# library.
20
-
21
- == Note on Patches/Pull Requests
22
-
23
- * Fork the project.
24
- * Make your feature addition or bug fix.
25
- * Add tests for it. This is important so I don't break it in a
26
- future version unintentionally.
27
- * Commit, do not mess with rakefile, version, or history.
28
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
29
- * Send me a pull request. Bonus points for topic branches.
30
-
31
- == Copyright
32
-
33
- Distributed under the Code Project Open License, which is similar to MIT or BSD. See LICENSE for full details (don't just take my word for it that it's similar to those licenses).
34
-
35
- == History
36
-
37
- === 1.0.0 - 2014-07-08
38
- * Migrate to new version of Jeweler for gem packaging
39
- * Merge jwroblewski's changes into a new multi-threaded simple random class
40
- * Change from Code Project Open License to CDDL-1.0[http://opensource.org/licenses/CDDL-1.0]
41
-
42
- === 0.10.0 - 2014-03-31
43
- * Sample from triangular distribution (thanks to benedictleejh[https://github.com/benedictleejh])
44
-
45
- === 0.9.3 - 2011-09-16
46
- * Sample from Dirichlet distribution with given set of parameters
47
-
48
- === 0.9.2 - 2011-09-06
49
- * Use microseconds for random seed
50
-
51
- === 0.9.1 - 2010-07-27
52
- * First stable release