Created
April 4, 2017 14:15
-
-
Save paulohrpinheiro/85a75c16be926aa534797de8beaff62f to your computer and use it in GitHub Desktop.
Quantos números aleatórios gero em 1 segundo? - Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require 'timeout' | |
how_many = 0 | |
rand_generator = Random.new | |
begin | |
Timeout.timeout(1) do | |
loop do | |
rand_generator.rand 100 | |
how_many += 1 | |
end | |
end | |
rescue Timeout::Error | |
puts how_many | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment