Module: Violence::Helpers

Included in:
Agent
Defined in:
lib/violence/helpers.rb

Instance Method Summary collapse

Instance Method Details

#powerlaw(k) ⇒ Object



10
11
12
# File 'lib/violence/helpers.rb', line 10

def powerlaw(k)
  (k + 1) * (rand ** k)
end

#randnObject

Normal distributed random, mu = 0 and sigma = 1



3
4
5
6
7
8
# File 'lib/violence/helpers.rb', line 3

def randn # Normal distributed random, mu = 0 and sigma = 1
  # Box-Muller transform
  u1 = 1-rand
  u2 = 1-rand
  Math.sqrt(-2 * Math.log(u1)) * Math.cos(2 * Math::PI * u2)
end