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 | 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.