Created
November 29, 2012 02:56
-
-
Save kimoto/4166480 to your computer and use it in GitHub Desktop.
乱数の出目が連続するときにどの位連続するときはしちゃうのか試す用コード
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
#!/bin/env ruby | |
# encoding: utf-8 | |
def random | |
[1,2,3,4,5,6].sample | |
end | |
last_val = -1 # last time value | |
cnt = 0 # repeated cnt | |
max_cnt = -1 # max repeated cnt | |
tries = 100000000 | |
tries.times{ |n| | |
# for debug | |
if n % 10000 == 0 | |
STDERR.puts "#{n} / #{tries} [#{(n.quo(tries)*100).to_i}%] done" | |
end | |
r = random() | |
if r == last_val | |
cnt += 1 | |
else | |
if cnt > max_cnt | |
max_cnt = cnt | |
end | |
cnt = 0 | |
end | |
puts "rand: #{r} (#{cnt + 1})" | |
last_val = r | |
} | |
puts "max repeated = #{max_cnt}" | |
STDERR.puts "max repeated = #{max_cnt}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment