kevinrutherford / coin-tossing

Demonstration of variation in a simple process

coin-tossing / sparky.rb
100644 20 lines (14 sloc) 0.29 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
require 'sparkline'
 
def zero_or_one() rand(2) end
 
def one_or_minus_one
  (zero_or_one * 2) - 1
end
 
def next_value(y_values)
  y_values[-1] + one_or_minus_one
end
 
def y_values
  result = [0]
  1000.times { result << next_value(result) }
  result
end
 
puts Sparkline.new(y_values).to_svg