Ruby file information output instance code

Source: Internet
Author: User

DEMO code:
[Code]
#! /Usr/bin/env ruby
COUNT = 10
Require 'benchmark'
$ Account_chars = ('A' .. 'Z'). to_a.delete_if {| 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
}
Output to: account.txt.
The output information format is 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.