I *heart* PowerShell
When I saw the example in I *heart* python , and the remark about PowerShell in it, I could not resist doing the same exercise in PowerShell :
$codes = @{}
# some existing coded for testing and make sure we have at least one duplicate
$existingCodes = 'poipoi','blinky'
$codes['poipoi']= 0
# Create new codes
$r = new-object random
(1..500)|% {
$tmp = ''
1..6 |% {$tmp += [char]$r.Next(97,123)}
$codes[$tmp]= 0
}
# Duplicates
$duplicates = $codes.keys|? {$existingCodes -contains $_}
# valid ones
$valid = $codes.keys|? {$existingCodes -notContains $_}
Remarks
- I use the same dictionary trick, only in PowerShell it is called a HashTable and is declared like this @{}
- As I was to lazy to type the Alphabet I created the letter list first :
- $letters = [char[]](97..122)
- but later as I needed a random character anyway, I included this logic directly in the loop
- As I suspect that we need the valid ones more as the Duplicates I store them in $valid
* Update * to filter out the letters (I missed in example above) the script again using $letters Without l or q
$Codes = @{}
$letters = [char[]](97..122) -notmatch 'l|q'
$r = new-object random
(1..500) |% {
$tmp = ''
1..6 |% {$tmp += $letters[($r.Next(0,24))]}
$codes[$tmp] = 0
}
So if you do not have (Iron)Python handy, you can use PowerShell as well to create a on-the-fly list of password-style codes for e-xamit.
Enjoy,
Greetings /\/\o\/\/