在这个新的冒险中,我需要尽可能快地填充这个矩阵。所以在我看来,我需要对变量做的是:
for ($r = 0 ; $r -lt 5 ; $r++){
new-variable r$r
for ($i = 0 ; $i -lt 5 ; $i++){
$rand = Get-Random -Minimum 0 -Maximum 50
r$r += "$rand,"
}
}
但它不起作用,它告诉我r0
> 不是已知的 cmdlet。这应该创建 r0...r4 变量,这意味着 row0...row4 并且每个 rn 将填充一个随机数,后跟一个逗号。
怎么做?
而且......我真的不知道我是否以正确的方式做我的矩阵,但这就是我现在所拥有的:
$r1 = ""
for ($i = 0 ; $i -lt 4 ; $i++){
$rand = Get-Random -Minimum 0 -Maximum 50
$r1 += "$rand,"
}
$r1 = $r1.Replace(" ",",")
$r1 = $r1.TrimEnd(',')
# Write-Host $r1
$r2 = ""
for ($i = 0 ; $i -lt 4 ; $i++){
$rand = Get-Random -Minimum 0 -Maximum 50
$r2 += "$rand,"
}
$r2 = $r2.Replace(" ",",")
$r2 = $r2.TrimEnd(',')
# Write-Host $r2
$matrix = @(($r1),($r2))
foreach ($g in $matrix) {$g}