Skip to content

Instantly share code, notes, and snippets.

@AndrewBarfield
Created April 29, 2012 17:37
Show Gist options
  • Save AndrewBarfield/2552163 to your computer and use it in GitHub Desktop.
Save AndrewBarfield/2552163 to your computer and use it in GitHub Desktop.
PowerShell: Generate a set of N random integers between -9 and 9
cls
$N = 5;
# --------------------------------------------------------------------------------
#
# FUNCTION NAME: GenerateSet
#
# DESCRIPTION: Generates a set of N random integers between -9 and 9
#
# --------------------------------------------------------------------------------
function GenerateSet
{
Write-Host –NoNewLine "S = {"
for($i=0; $i -le $N; $i++)
{
$rnd = Get-Random -minimum -9 -maximum 9
if($i -lt $N)
{
Write-Host –NoNewLine $rnd", "
}
else
{
Write-Host –NoNewLine $rnd
}
}
Write-Host "}"
}
GenerateSet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment