Skip to content

Instantly share code, notes, and snippets.

@rkotov93
Last active March 5, 2016 12:45
Show Gist options
  • Select an option

  • Save rkotov93/7aa09af1e9955a72f215 to your computer and use it in GitHub Desktop.

Select an option

Save rkotov93/7aa09af1e9955a72f215 to your computer and use it in GitHub Desktop.
def random_sum
Thread.current[:output] = ""
10.times do
a = Random.rand(1..1000)
b = Random.rand(1..1000)
Thread.current[:output] += "#{a} + #{b} = #{a + b}\n"
end
sleep 3
end
def fact(n)
n == 0 ? 1 : n*fact(n-1)
end
def random_fact
Thread.current[:output] = ""
10.times do
x = Random.rand(5..10)
Thread.current[:output] += "#{x}! = #{fact(x)}\n"
end
sleep 3
end
t1 = Thread.new { random_sum }
t2 = Thread.new { random_fact }
t1.join
t2.join
puts t1[:output]
puts '==='
puts t2[:output]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment