我开发了一个纸牌组来在Visio上玩棋盘游戏,但是我和我的 friend 们对纸牌的“感觉”并不好。
我使用的代码如下(我简化了代码,但我对包含数字的卡片的正字使用相同的算法,如果需要,我可以添加它):
# Actions
$CONFIG_ACTIONS = @{
"pool"=9
"interim"=9
"bis"=9
"parc"=18
"sell"=18
"barrier"=18
}
$unshuffeledListAction = [System.Collections.ArrayList]@()
foreach ($actionToAdd in $CONFIG_ACTIONS.Keys) {
[int]$howManyTime = $($CONFIG_ACTIONS[$actionToAdd])
for($i=0;$i -lt $howManyTime;$i++) {
$unshuffeledListAction.Add($actionToAdd) | out-null
}
}
# Request random number between 0 and 65535
$requestURI = "https://qrng.anu.edu.au/API/jsonI.php?length=1&type=uint16"
# Randomize Cards: Try WebService
Try {
$random = $(Invoke-RestMethod -Uri $requestURI -Method GET).data
$shuffeledListActions = $unshuffeledListAction | Get-Random -Count $unshuffeledListAction.Count -SetSeed ($random[0])
} Catch {
Write-warning "Failed to called QRNG@ANU JSON API switching to local pseudo-random"
$shuffeledListActions = $unshuffeledListAction | Get-Random -Count $unshuffeledListAction.Count
}
我对安全性没有特殊需求,因为这是供个人使用而没有敏感信息,因此我可以使用WebServices,并且已经尝试过。
我的第一次洗牌尝试很简单:
$shuffeledListActions = $unshuffeledListAction | Get-Random -Count $unshuffeledListAction.Count
可以改善吗?调用量子随机数生成器服务的第二次尝试是否更好?
最佳答案
Get-Random -Count
很好。我可能会完全放弃Web服务调用。 PRNG非常好,从其他地方获取种子不会在这里发生太大变化。
关于arrays - 有什么方法可以改善此Powershell阵列随机播放方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61558941/