Sha256: 1f9b97bc893c8df1520692bfd86dde4bfd1532d97c163c2a7588e84960f20852

Contents?: true

Size: 582 Bytes

Versions: 6

Compression:

Stored size: 582 Bytes

Contents

require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'fathom'))
class Fathom::Distributions::DiscreteUniform
  extend Fathom::Distributions::SharedMethods
  class << self
    def rng
      @rng ||= GSL::Rng.alloc(GSL::Rng::MT19937_1999, Kernel.rand(100_000))
    end
    
    # Bounded from 0 to size - 1
    def rand(size)
      value = get_rand(size)
      while value < 0 or value >= size
        value = get_rand(size)
      end
      value
    end
    
    protected
      def get_rand(size)
        (rng.ugaussian / size).floor + 1
      end
    
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
fathom-0.3.7 lib/fathom/distributions/discrete_uniform.rb
fathom-0.3.6 lib/fathom/distributions/discrete_uniform.rb
fathom-0.3.4 lib/fathom/distributions/discrete_uniform.rb
fathom-0.3.3 lib/fathom/distributions/discrete_uniform.rb
fathom-0.3.2 lib/fathom/distributions/discrete_uniform.rb
fathom-0.3.1 lib/fathom/distributions/discrete_uniform.rb