Class: LaunchDarkly::Impl::Sampler

Inherits:
Object
  • Object
show all
Defined in:
lib/ldclient-rb/impl/sampler.rb

Overview

Since:

  • 5.5.0

Instance Method Summary collapse

Constructor Details

#initialize(random) ⇒ Sampler

Returns a new instance of Sampler.

Parameters:

  • random (Random)

Since:

  • 5.5.0



7
8
9
# File 'lib/ldclient-rb/impl/sampler.rb', line 7

def initialize(random)
  @random = random
end

Instance Method Details

#sample(ratio) ⇒ Boolean

Parameters:

  • ratio (Int)

Returns:

  • (Boolean)

Since:

  • 5.5.0



16
17
18
19
20
21
22
# File 'lib/ldclient-rb/impl/sampler.rb', line 16

def sample(ratio)
  return false unless ratio.is_a? Integer
  return false if ratio <= 0
  return true if ratio == 1

  @random.rand(1.0) < 1.0 / ratio
end