Created
June 24, 2011 11:59
-
-
Save webgago/1044642 to your computer and use it in GitHub Desktop.
passwords generator
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
$file_mode = 'w' | |
$file_path = 'file.tmp' | |
$lines = [] | |
def generate_lines | |
for i in 0..999 | |
$lines << ("0".."z").to_a.sample((10..20).to_a.sample).join('') | |
end | |
end | |
def open_file | |
$file = File.open($file_path, $file_mode) | |
end | |
def close_file | |
$file.close | |
end | |
def print_lines | |
for i in 0..999 | |
line_no = i + 1 | |
print line_no.to_s + ". " + $lines[i].to_s + "\n" | |
end | |
end | |
def write_lines | |
for i in 0..999 | |
$file.puts $lines[i] | |
end | |
end | |
def show_statistic | |
lengths = [] | |
for i in 0..999 | |
lengths << $lines[i].length | |
end | |
lengths.sort! | |
for i in 0..lengths.uniq.size | |
print lengths.uniq[i].to_s + "\n" | |
end | |
lengths_hash = {} | |
for i in 0..999 | |
if lengths_hash[lengths[i]] | |
lengths_hash[lengths[i]] += 1 | |
else | |
lengths_hash[lengths[i]] = 1 | |
end | |
end | |
print "Sootnoshenie po dline paroliya"+ "\n" | |
for i in lengths_hash | |
print i[0].to_s + ": " + i[1].to_s + "\n" | |
end | |
end | |
def create_passwords_file | |
open_file | |
generate_lines | |
write_lines | |
close_file | |
show_statistic | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment