Created
May 1, 2019 21:34
-
-
Save PrzemyslawKlys/5a6e3c51f8a6f68df1bfe426f1ebc03e to your computer and use it in GitHub Desktop.
Small example of skiping $array+=
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Surname list from a web site | |
$uri = "https://names.mongabay.com/most_common_surnames.htm" | |
$data = Invoke-WebRequest $uri | |
$table_surname = $data.ParsedHtml.getElementsByTagName("table") | Select -first 1 | |
[array]$table_surname = $table_surname | select -ExpandProperty innertext | |
$table_surname = $table_surname.Replace("SurnameApproximate", "").replace("Number%", "").replace("FrequencyRank", "") | |
$table_surname = $table_surname -split "`n" | |
[regex]$filter = '[^a-zA-Z]' | |
$surname_list = $table_surname -replace $filter | |
# Firstname List | |
$uri = "https://names.mongabay.com/male_names_alpha.htm" | |
$data = Invoke-WebRequest $uri | |
$table_firstname = $data.ParsedHtml.getElementsByTagName("table") | Select -first 1 | |
[array]$table_firstname = $table_firstname | select -ExpandProperty innertext | |
$table_firstname = $table_firstname.Replace("Name%", "").replace("NumberRank", "").replace("FrequencyApproximate", "") | |
$table_firstname = $table_firstname -split "`n" | |
[regex]$filter = '[^a-zA-Z]' | |
$firstname_list = $table_firstname -replace $filter | |
$surname_count = $surname_list.count | |
$firstname_count = $firstname_list.count | |
$number_of_name = 1..10000000 | |
$array = @( | |
# This will be added to array (there is nothing on the left side) | |
"Firstname,surname" | |
$number_of_name | % { | |
$random_surname_num = get-random -Maximum $surname_count | |
$random_surname = $surname_list[$random_surname_num] | |
$random_firstname_num = get-random -Maximum $firstname_count | |
$random_firstname = $firstname_list[$random_surname_num] | |
# this will be added to $Array | |
$random_firstname + "," + $random_surname | |
} | |
) | |
$array |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment