-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbestRandom.ps1
More file actions
43 lines (36 loc) · 954 Bytes
/
bestRandom.ps1
File metadata and controls
43 lines (36 loc) · 954 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function Get-CryptoRand{
Param ([Parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
$Rolls = 20,
[Parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
$Bound= 32..126
)
Begin{
function Randomize-List{
Param([array]$InputList)
return $InputList | Get-Random -SetSeed ([Environment]::TickCount) -Count $InputList.Count;
}
function rand{
$bytes = new-object "System.Byte[]" $Rolls
$rnd = new-object System.Security.Cryptography.RNGCryptoServiceProvider
$rnd.GetBytes($bytes)
$bytes = $bytes | sort -Unique | Where-Object {$_ -in $Bound}
$bytes
}
}
Process{
$TMP = @()
while($TMP.count -le $Rolls){
$TMP += rand
Write-Verbose $TMP.Length
}
}
End{
$Out = @()
$out = Randomize-List -InputList $TMP
$Out = $Out |Select-Object -First $Rolls
$Out
}
}
Get-CryptoRand