Last active
August 29, 2015 14:06
-
-
Save pwhe23/0758a860aba3abaf20ca to your computer and use it in GitHub Desktop.
Random.ps1
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
| Add-Type -AssemblyName 'System.Windows.Forms' | |
| Add-Type -AssemblyName 'Microsoft.VisualBasic' | |
| $maximum = [int][Microsoft.VisualBasic.Interaction]::InputBox("Enter Maximum (inclusive)", "Max", "5") | |
| $popup = $true | |
| function Main() { | |
| if ($Host.Name -eq "Windows Powershell ISE Host") { | |
| Clear-Host | |
| } | |
| PrintList(GetRandom($maximum)) | |
| } | |
| function GetRandom([int] $max, [int] $seed = 0) { | |
| if ($seed -eq 0) { | |
| $ticks = [DateTime]::Now.Ticks.ToString() | |
| $ticks = ([regex]::Matches($ticks,'.','RightToLeft') | ForEach {$_.value}) -join '' | |
| $seed = $ticks.Substring(0, 9) | |
| } | |
| Get-Random -SetSeed $seed | Out-Null | |
| $list = New-Object System.Collections.Generic.List[System.String] | |
| while ($list.Count -lt $max) { | |
| $rand = Get-Random -Minimum 1 -Maximum ($max+1) | |
| if (-not $list.Contains($rand)) { | |
| $list.Add($rand) | |
| } | |
| } | |
| return $list | |
| } | |
| function PrintList($list) { | |
| $index = 0 | |
| while ($index -lt $list.Count) { | |
| $msg = ($index+1).ToString().PadLeft(2) + ": " + $list[$index] | |
| Write-Host $msg | |
| if ($popup -eq $true) { | |
| $continue = [System.Windows.Forms.MessageBox]::Show($list[$index], "Continue?", 4) | |
| if ($continue -eq "No") { | |
| $popup = $false | |
| #return | |
| } | |
| } | |
| $index += 1 | |
| } | |
| } | |
| Main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment