记录一下。
#encoding:utf-8
REGIN_CODE = '530101'
BIRTHDAY = '19970701'
TIMES = 5
def get_check_char(input)
factors = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
checknum = ['1', '0', 'X' , '9', '8', '7', '6', '5', '4', '3', '2']
checksum = 0
input.chars.each_with_index do |e,i|
break if i >= 17
checksum += (e.to_i * factors[i])
end
checknum[checksum % 11]
end
def check_valid?(input)
input.slice(17,1) == get_check_char(input)
end
TIMES.times do |x|
precode = format("%06d%08d%02d%01d",REGIN_CODE,BIRTHDAY,rand(100),rand(10))
checkcode = get_check_char(precode)
puts precode + checkcode
#puts check_valid?(precode + checkcode)
end
4317

被折叠的 条评论
为什么被折叠?



