Class: Planout::OpRandom
Constant Summary
collapse
- LongScale =
Float(0xFFFFFFFFFFFFFFF)
Instance Attribute Summary
Attributes inherited from Operator
#args
Instance Method Summary
collapse
Methods inherited from OpSimple
#execute, #simple_execute
Methods inherited from Operator
#execute, #initialize
Instance Method Details
#get_hash(appended_unit = nil) ⇒ Object
14
15
16
17
18
19
20
21
|
# File 'lib/planout/op_random.rb', line 14
def get_hash(appended_unit = nil)
salt = @parameters[:salt]
salty = "#{@mapper.experiment_salt}.#{salt}"
unit_str = get_unit(appended_unit).join('.')
x = "#{salty}.#{unit_str}"
last_hex = (Digest::SHA1.hexdigest(x))[0..14]
last_hex.to_i(16)
end
|
23
24
25
26
|
# File 'lib/planout/op_random.rb', line 23
def get_uniform(min_val = 0.0, max_val = 1.0, appended_unit = nil)
zero_to_one = self.get_hash(appended_unit)/LongScale
min_val + (max_val-min_val) * zero_to_one
end
|
#get_unit(appended_unit = nil) ⇒ Object
7
8
9
10
11
12
|
# File 'lib/planout/op_random.rb', line 7
def get_unit(appended_unit = nil)
unit = @parameters[:unit]
unit = [unit] if !unit.is_a? Array
unit += appended_unit if appended_unit != nil
unit
end
|