Ruby for file information output instance code

Source: Internet
Author: User
Tags benchmark rand


The data is random, so each record will be different.



Demo Code:



[Code]



#!/usr/bin/env Ruby
COUNT = Ten
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 WHI Le password =~/^ (.) \1\1\1\1$/
Password
End
accounts = {}
lines = []
puts Benchmark::caption
puts benchmark.measure { br> 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 does |char, chars|
account = [char]
chars. Each do |char, chars|
Account << Char
Chars.each does |char, chars|
Account << char
Chars.each do |char, chars|
A Ccount << Char
Chars.each do |char, chars|
Account << char
Chars.each do |char, password|
Acco Unt << 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 {
op En ' 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.