Ruby for file information output instance Code _ruby topic

Source: Internet
Author: User
Tags benchmark rand
Demo Code:
[Code]
#!/usr/bin/env Ruby
COUNT = 10
Require ' benchmark '
$account _chars = (' A ' ... ') Z '). to_a.delete_if {|c| c =~/[aeiouy]/}
# $password _chars = (' 0 '. 9 '). to_a
$password _chars = array.new
$password _chars[0..9] = (' 0 ' ... ') 9 '). to_a
$password _chars[10..36] = (' A '.. ' Z '). to_a
def Account_char
$account _chars[rand ($account _chars.length)]
End
def Password_char
$password _chars[rand ($password _chars.length)]
End
def Account_chars
Account_chars = []
6.times {|c| account_chars << Account_char}
Account_chars
End
def password
Begin
Begin
Password = ' '
Password << Password_char
End While password = ' 0 '
4.times {password << Password_char}
End While password =~/^ (.) \1\1\1\1$/
Password
End
accounts = {}
lines = []
Puts Benchmark::caption
Puts Benchmark.measure {
Count.times do
i = 0
Account_chars.inject (accounts) do |a, c|
i + 1
i = = 6? A[C] = Password:a[c] | | = {}
End
End
}
Puts Benchmark.measure {
Accounts.each do |char, chars|
account = [Char]
Chars.each do |char, chars|
Account << Char
Chars.each do |char, chars|
Account << Char
Chars.each do |char, chars|
Account << Char
Chars.each do |char, chars|
Account << Char
Chars.each do |char, password|
Account << Char
Lines << "#{account.join}\t#{password}\r\n"
Account.pop
End
Account.pop
End
Account.pop
End
Account.pop
End
Account.pop
End
End
}
Puts Benchmark.measure {
Open ' account.txt ', ' WB ' do |f|
F.print Lines.delete_at (rand (lines.length)) until Lines.empty?
End
}
Run after output to: Account.txt file.
The output information is formatted as follows:
The data is random, so each record will be different.
SZQGMC XC6KP
HLVGTZ HCU30
KTSNNF Lsnvs
KWMHRQ 3sm07
Bttzcz Dymuh
DMKPVN GMJHL
Kcfkdr x8x8v
VMMJHB x1d65
Srcpgz T2IP6
WLRMBT 7ya2y
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.