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