gen-text 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/README.md +1 -1
  2. data/lib/gen_text/vm.rb +3 -8
  3. metadata +2 -2
data/README.md CHANGED
@@ -231,5 +231,5 @@ and "/" instead of "|":
231
231
  Links
232
232
  -----
233
233
 
234
- - [Documentation](http://www.rubydoc.info/gems/gen-text/0.0.7)
234
+ - [Documentation](http://www.rubydoc.info/gems/gen-text/0.0.8)
235
235
  - [Source code](https://github.com/LavirtheWhiolet/gen-text)
@@ -286,14 +286,9 @@ module GenText
286
286
  # @param [Array<Array<(Numeric, Object)>>] weights_and_items
287
287
  # @return [Array<(Numeric, Object)>]
288
288
  def sample_weighed(weights_and_items)
289
- weight_sum = weights_and_items.map(&:first).reduce(:+)
290
- chosen_partial_weight_sum = rand(0...weight_sum)
291
- current_partial_weight_sum = 0
292
- weights_and_items.find do |weight, item|
293
- current_partial_weight_sum += weight
294
- current_partial_weight_sum > chosen_partial_weight_sum
295
- end or
296
- weights_and_items.last
289
+ # The algorithm is described in
290
+ # http://utopia.duth.gr/~pefraimi/research/data/2007EncOfAlg.pdf
291
+ weights_and_items.max_by { |weight, item| rand ** (1.0 / weight) }
297
292
  end
298
293
 
299
294
  def inspect_instruction(instruction)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gen-text
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-07-09 00:00:00.000000000 Z
12
+ date: 2016-07-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: parse-framework